github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/hugolib/page__fragments_test.go (about)

     1  // Copyright 2023 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package hugolib
    15  
    16  import "testing"
    17  
    18  // #10794
    19  func TestFragmentsAndToCCrossSiteAccess(t *testing.T) {
    20  	files := `
    21  -- hugo.toml --
    22  baseURL = "https://example.com"
    23  disableKinds = ["taxonomy", "term", "home"]
    24  defaultContentLanguage = "en"
    25  defaultContentLanguageInSubdir = true
    26  [languages]
    27  [languages.en]
    28  weight = 1
    29  [languages.fr]
    30  weight = 2
    31  -- content/p1.en.md --
    32  ---
    33  title: "P1"
    34  outputs: ["HTML", "JSON"]
    35  ---
    36  
    37  ## Heading 1 EN
    38  
    39  -- content/p1.fr.md --
    40  ---
    41  title: "P1"
    42  outputs: ["HTML", "JSON"]
    43  ---
    44  
    45  ## Heading 1 FR
    46  -- layouts/_default/single.html --
    47  HTML
    48  -- layouts/_default/single.json --
    49  {{ $secondSite := index .Sites 1 }}
    50  {{ $p1 := $secondSite.GetPage "p1" }}
    51  ToC: {{ $p1.TableOfContents }}
    52  Fragments : {{ $p1.Fragments.Identifiers }}
    53  
    54  
    55  
    56  	
    57  `
    58  
    59  	b := NewIntegrationTestBuilder(
    60  		IntegrationTestConfig{
    61  			TxtarString: files,
    62  			T:           t,
    63  		},
    64  	).Build()
    65  
    66  	b.AssertFileContent("public/en/p1/index.html", "HTML")
    67  	b.AssertFileContent("public/en/p1/index.json", "ToC: <nav id=\"TableOfContents\">\n  <ul>\n    <li><a href=\"#heading-1-fr\">Heading 1 FR</a></li>\n  </ul>\n</nav>\nFragments : [heading-1-fr]")
    68  
    69  }