| 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 paths_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/hugolib" |
| 20 |
) |
| 21 |
|
| 22 |
func TestRemovePathAccents(t *testing.T) { |
| 23 |
t.Parallel() |
| 24 |
|
| 25 |
files := ` |
| 26 |
-- hugo.toml -- |
| 27 |
disableKinds = ["taxonomy", "term"] |
| 28 |
defaultContentLanguage = "en" |
| 29 |
defaultContentLanguageInSubdir = true |
| 30 |
[languages] |
| 31 |
[languages.en] |
| 32 |
weight = 1 |
| 33 |
[languages.fr] |
| 34 |
weight = 2 |
| 35 |
removePathAccents = true |
| 36 |
-- content/διακριτικός.md -- |
| 37 |
-- content/διακριτικός.fr.md -- |
| 38 |
-- layouts/single.html -- |
| 39 |
{{ .Language.Lang }}|Single. |
| 40 |
-- layouts/list.html -- |
| 41 |
List |
| 42 |
` |
| 43 |
b := hugolib.Test(t, files) |
| 44 |
|
| 45 |
b.AssertFileContent("public/en/διακριτικός/index.html", "en|Single") |
| 46 |
b.AssertFileContent("public/fr/διακριτικος/index.html", "fr|Single") |
| 47 |
} |
| 48 |
|
| 49 |
func TestDisablePathToLower(t *testing.T) { |
| 50 |
t.Parallel() |
| 51 |
|
| 52 |
files := ` |
| 53 |
-- hugo.toml -- |
| 54 |
disableKinds = ["taxonomy", "term"] |
| 55 |
defaultContentLanguage = "en" |
| 56 |
defaultContentLanguageInSubdir = true |
| 57 |
[languages] |
| 58 |
[languages.en] |
| 59 |
weight = 1 |
| 60 |
[languages.fr] |
| 61 |
weight = 2 |
| 62 |
disablePathToLower = true |
| 63 |
-- content/MySection/MyPage.md -- |
| 64 |
-- content/MySection/MyPage.fr.md -- |
| 65 |
-- content/MySection/MyBundle/index.md -- |
| 66 |
-- content/MySection/MyBundle/index.fr.md -- |
| 67 |
-- layouts/single.html -- |
| 68 |
{{ .Language.Lang }}|Single. |
| 69 |
-- layouts/list.html -- |
| 70 |
{{ .Language.Lang }}|List. |
| 71 |
` |
| 72 |
b := hugolib.Test(t, files) |
| 73 |
|
| 74 |
b.AssertFileContent("public/en/mysection/index.html", "en|List") |
| 75 |
b.AssertFileContent("public/en/mysection/mypage/index.html", "en|Single") |
| 76 |
b.AssertFileContent("public/fr/MySection/index.html", "fr|List") |
| 77 |
b.AssertFileContent("public/fr/MySection/MyPage/index.html", "fr|Single") |
| 78 |
b.AssertFileContent("public/en/mysection/mybundle/index.html", "en|Single") |
| 79 |
b.AssertFileContent("public/fr/MySection/MyBundle/index.html", "fr|Single") |
| 80 |
} |
| 81 |
|
| 82 |
func TestPrefixIdentifiersContent(t *testing.T) { |
| 83 |
t.Parallel() |
| 84 |
|
| 85 |
files := ` |
| 86 |
-- hugo.toml -- |
| 87 |
disableKinds = ["taxonomy", "term"] |
| 88 |
defaultContentLanguage = "en" |
| 89 |
defaultContentLanguageInSubdir = true |
| 90 |
[languages] |
| 91 |
[languages.en] |
| 92 |
weight = 1 |
| 93 |
[languages.fr] |
| 94 |
weight = 2 |
| 95 |
-- content/p1.md -- |
| 96 |
--- |
| 97 |
title: p1 default |
| 98 |
--- |
| 99 |
-- content/p1._language_fr_.md -- |
| 100 |
--- |
| 101 |
title: p1 french |
| 102 |
--- |
| 103 |
-- layouts/single.html -- |
| 104 |
{{ .Language.Lang }}|{{ .Title }}|Single. |
| 105 |
-- layouts/list.html -- |
| 106 |
List |
| 107 |
` |
| 108 |
b := hugolib.Test(t, files) |
| 109 |
|
| 110 |
b.AssertFileContent("public/en/p1/index.html", "en|p1 default|Single") |
| 111 |
b.AssertFileContent("public/fr/p1/index.html", "fr|p1 french|Single") |
| 112 |
} |
| 113 |
|
| 114 |
func TestPrefixIdentifiersLayouts(t *testing.T) { |
| 115 |
t.Parallel() |
| 116 |
|
| 117 |
files := ` |
| 118 |
-- hugo.toml -- |
| 119 |
disableKinds = ["taxonomy", "term"] |
| 120 |
defaultContentLanguage = "en" |
| 121 |
defaultContentLanguageInSubdir = true |
| 122 |
[languages] |
| 123 |
[languages.en] |
| 124 |
weight = 1 |
| 125 |
[languages.fr] |
| 126 |
weight = 2 |
| 127 |
-- content/p1.md -- |
| 128 |
--- |
| 129 |
title: p1 |
| 130 |
--- |
| 131 |
-- content/p1.fr.md -- |
| 132 |
--- |
| 133 |
title: p1 fr |
| 134 |
--- |
| 135 |
-- layouts/single.html -- |
| 136 |
default|{{ .Title }}| |
| 137 |
-- layouts/single._language_fr_.html -- |
| 138 |
french layout|{{ .Title }}| |
| 139 |
-- layouts/list.html -- |
| 140 |
List |
| 141 |
` |
| 142 |
b := hugolib.Test(t, files) |
| 143 |
|
| 144 |
b.AssertFileContent("public/en/p1/index.html", "default|p1|") |
| 145 |
b.AssertFileContent("public/fr/p1/index.html", "french layout|p1 fr|") |
| 146 |
} |
| 147 |
|
| 148 |
func TestIssue13596(t *testing.T) { |
| 149 |
t.Parallel() |
| 150 |
|
| 151 |
files := ` |
| 152 |
-- hugo.toml -- |
| 153 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 154 |
-- content/p1/index.md -- |
| 155 |
--- |
| 156 |
title: p1 |
| 157 |
--- |
| 158 |
-- content/p1/a.1.txt -- |
| 159 |
-- content/p1/a.2.txt -- |
| 160 |
-- layouts/all.html -- |
| 161 |
{{ range .Resources.Match "*" }}{{ .Name }}|{{ end }} |
| 162 |
` |
| 163 |
|
| 164 |
b := hugolib.Test(t, files) |
| 165 |
|
| 166 |
b.AssertFileContent("public/p1/index.html", "a.1.txt|a.2.txt|") |
| 167 |
b.AssertFileExists("public/p1/a.1.txt", true) |
| 168 |
b.AssertFileExists("public/p1/a.2.txt", true) // fails |
| 169 |
} |