github.com/neohugo/neohugo@v0.123.8/hugolib/page__fragments_test.go (about)

     1  // Copyright 2024 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  
    70  // Issue #10866
    71  func TestTableOfContentsWithIncludedMarkdownFile(t *testing.T) {
    72  	files := `
    73  -- hugo.toml --
    74  baseURL = "https://example.com"
    75  disableKinds = ["taxonomy", "term", "home"]
    76  -- content/p1.md --
    77  ---
    78  title: "P1"
    79  ---
    80  
    81  ## Heading P1 1
    82  {{% include "p2" %}}
    83  
    84  -- content/p2.md --
    85  ---
    86  title: "P2"
    87  ---
    88  
    89  ### Heading P2 1
    90  ### Heading P2 2
    91  
    92  -- layouts/shortcodes/include.html --
    93  {{ with site.GetPage (.Get 0) }}{{ .RawContent }}{{ end }}
    94  -- layouts/_default/single.html --
    95  Fragments: {{ .Fragments.Identifiers }}|
    96  
    97  
    98  	
    99  `
   100  
   101  	b := NewIntegrationTestBuilder(
   102  		IntegrationTestConfig{
   103  			TxtarString: files,
   104  			T:           t,
   105  		},
   106  	).Build()
   107  
   108  	b.AssertFileContent("public/p1/index.html", "Fragments: [heading-p1-1 heading-p2-1 heading-p2-2]|")
   109  	b.AssertFileContent("public/p2/index.html", "Fragments: [heading-p2-1 heading-p2-2]|")
   110  }