| 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/single.html -- |
| 47 |
HTML |
| 48 |
-- layouts/single.json -- |
| 49 |
{{ $secondSite := index hugo.Sites 1 }} |
| 50 |
{{ $p1 := $secondSite.GetPage "p1" }} |
| 51 |
ToC: {{ $p1.TableOfContents }} |
| 52 |
Fragments : {{ $p1.Fragments.Identifiers }} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
` |
| 58 |
|
| 59 |
b := Test(t, files) |
| 60 |
|
| 61 |
b.AssertFileContent("public/en/p1/index.html", "HTML") |
| 62 |
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]") |
| 63 |
} |
| 64 |
|
| 65 |
// Issue #10866 |
| 66 |
func TestTableOfContentsWithIncludedMarkdownFile(t *testing.T) { |
| 67 |
files := ` |
| 68 |
-- hugo.toml -- |
| 69 |
baseURL = "https://example.com" |
| 70 |
disableKinds = ["taxonomy", "term", "home"] |
| 71 |
-- content/p1.md -- |
| 72 |
--- |
| 73 |
title: "P1" |
| 74 |
--- |
| 75 |
|
| 76 |
## Heading P1 1 |
| 77 |
{{% include "p2" %}} |
| 78 |
|
| 79 |
-- content/p2.md -- |
| 80 |
--- |
| 81 |
title: "P2" |
| 82 |
--- |
| 83 |
|
| 84 |
### Heading P2 1 |
| 85 |
### Heading P2 2 |
| 86 |
|
| 87 |
-- layouts/_shortcodes/include.html -- |
| 88 |
{{ with site.GetPage (.Get 0) }}{{ .RawContent }}{{ end }} |
| 89 |
-- layouts/single.html -- |
| 90 |
Fragments: {{ .Fragments.Identifiers }}| |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
` |
| 95 |
|
| 96 |
b := Test(t, files) |
| 97 |
|
| 98 |
b.AssertFileContent("public/p1/index.html", "Fragments: [heading-p1-1 heading-p2-1 heading-p2-2]|") |
| 99 |
b.AssertFileContent("public/p2/index.html", "Fragments: [heading-p2-1 heading-p2-2]|") |
| 100 |
} |