Debian Codegraph @

hugolib/language_content_dir_test.go

raw
1 // Copyright 2019 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 (
17 "testing"
18 )
19
20 func TestLanguageContentRoot(t *testing.T) {
21 files := `
22 -- hugo.toml --
23 baseURL = "https://example.org/"
24 defaultContentLanguage = "en"
25 defaultContentLanguageInSubdir = true
26 [languages]
27 [languages.en]
28 weight = 10
29 contentDir = "content/en"
30 [languages.nn]
31 weight = 20
32 contentDir = "content/nn"
33 -- content/en/_index.md --
34 ---
35 title: "Home"
36 ---
37 -- content/nn/_index.md --
38 ---
39 title: "Heim"
40 ---
41 -- content/en/myfiles/file1.txt --
42 file 1 en
43 -- content/en/myfiles/file2.txt --
44 file 2 en
45 -- content/nn/myfiles/file1.txt --
46 file 1 nn
47 -- layouts/home.html --
48 Title: {{ .Title }}|
49 Len Resources: {{ len .Resources }}|
50 {{ range $i, $e := .Resources }}
51 {{ $i }}|{{ .RelPermalink }}|{{ .Content }}|
52 {{ end }}
53
54 `
55 b := Test(t, files)
56 b.AssertFileContent("public/en/index.html", "Home", "0|/en/myfiles/file1.txt|file 1 en|\n\n1|/en/myfiles/file2.txt|file 2 en|")
57 b.AssertFileContent("public/nn/index.html", "Heim", "0|/nn/myfiles/file1.txt|file 1 nn|\n\n1|/en/myfiles/file2.txt|file 2 en|")
58 }
59
60 func TestContentMountMerge(t *testing.T) {
61 t.Parallel()
62
63 files := `
64 -- hugo.toml --
65 baseURL = 'https://example.org/'
66 locale = 'en-us'
67 title = 'Hugo Forum Topic #37225'
68 theme = 'mytheme'
69
70 disableKinds = ['sitemap','RSS','taxonomy','term']
71 defaultContentLanguage = 'en'
72 defaultContentLanguageInSubdir = true
73
74 [languages.en]
75 label = 'English'
76 weight = 1
77 [languages.de]
78 label = 'Deutsch'
79 weight = 2
80 [languages.nl]
81 label = 'Nederlands'
82 weight = 3
83
84 # EN content
85 [[module.mounts]]
86 source = 'content/en'
87 target = 'content'
88 [module.mounts.sites.matrix]
89 languages = 'en'
90
91 # DE content
92 [[module.mounts]]
93 source = 'content/de'
94 target = 'content'
95 [module.mounts.sites.matrix]
96 languages = 'de'
97
98 # This fills in the gaps in DE content with EN content
99 [[module.mounts]]
100 source = 'content/en'
101 target = 'content'
102 [module.mounts.sites.matrix]
103 languages = 'de'
104
105 # NL content
106 [[module.mounts]]
107 source = 'content/nl'
108 target = 'content'
109 [module.mounts.sites.matrix]
110 languages = 'nl'
111
112 # This should fill in the gaps in NL content with EN content
113 [[module.mounts]]
114 source = 'content/en'
115 target = 'content'
116 [module.mounts.sites.matrix]
117 languages = 'nl'
118
119 -- content/de/_index.md --
120 ---
121 title: "home (de)"
122 ---
123 -- content/de/p1.md --
124 ---
125 title: "p1 (de)"
126 ---
127 -- content/en/_index.md --
128 ---
129 title: "home (en)"
130 ---
131 -- content/en/p1.md --
132 ---
133 title: "p1 (en)"
134 ---
135 -- content/en/p2.md --
136 ---
137 title: "p2 (en)"
138 ---
139 -- content/en/p3.md --
140 ---
141 title: "p3 (en)"
142 ---
143 -- content/nl/_index.md --
144 ---
145 title: "home (nl)"
146 ---
147 -- content/nl/p1.md --
148 ---
149 title: "p1 (nl)"
150 ---
151 -- content/nl/p3.md --
152 ---
153 title: "p3 (nl)"
154 ---
155 -- layouts/home.html --
156 {{ .Title }}: {{ site.Language.Lang }}: {{ range site.RegularPages }}{{ .Title }}|{{ end }}:END
157 -- themes/mytheme/config.toml --
158 [[module.mounts]]
159 source = 'content/nlt'
160 target = 'content'
161 [module.mounts.sites.matrix]
162 languages = 'nl'
163 -- themes/mytheme/content/nlt/p3.md --
164 ---
165 title: "p3 theme (nl)"
166 ---
167 -- themes/mytheme/content/nlt/p4.md --
168 ---
169 title: "p4 theme (nl)"
170 ---
171 `
172
173 b := Test(t, files)
174
175 b.AssertFileContent("public/nl/index.html", `home (nl): nl: p1 (nl)|p2 (en)|p3 (nl)|p4 theme (nl)|:END`)
176 b.AssertFileContent("public/de/index.html", `home (de): de: p1 (de)|p2 (en)|p3 (en)|:END`)
177 b.AssertFileContent("public/en/index.html", `home (en): en: p1 (en)|p2 (en)|p3 (en)|:END`)
178 }
179
180 // Issue 14681
181 func TestPublishMultilingualSectionCreation(t *testing.T) {
182 t.Parallel()
183
184 files := `
185 -- hugo.toml --
186 capitalizeListTitles = false
187 pluralizeListTitles = false
188 disableKinds = ['rss','sitemap','taxonomy','term']
189
190 defaultContentLanguage = "fr"
191 defaultContentLanguageInSubdir = true
192
193 [languages.fr]
194 contentDir = "content/fr"
195 weight = 1
196
197 [languages.en]
198 contentDir = "content/en"
199 weight = 2
200
201 [languages.de]
202 contentDir = "content/de"
203 weight = 3
204 -- layouts/home.html --
205 HOME {{ .Language.Name }}
206 -- layouts/page.html --
207 {{ .Title }} {{ .Language.Name }}
208 -- layouts/section.html --
209 {{ .Title }} {{ .Language.Name }}
210 -- content/de/s1/p1.md --
211 ---
212 title: p1
213 ---
214 -- content/en/s1/p2.md --
215 ---
216 title: p2
217 ---
218 -- content/fr/s1/p3.md --
219 ---
220 title: p3
221 ---
222 `
223
224 b := Test(t, files)
225
226 b.AssertFileContent("public/de/index.html", "HOME de")
227 b.AssertFileContent("public/de/s1/index.html", "s1 de")
228 b.AssertFileContent("public/de/s1/p1/index.html", "p1 de")
229
230 b.AssertFileContent("public/en/index.html", "HOME en")
231 b.AssertFileContent("public/en/s1/index.html", "s1 en") // fail (file does not exist)
232 b.AssertFileContent("public/en/s1/p2/index.html", "p2 en")
233
234 b.AssertFileContent("public/fr/index.html", "HOME fr")
235 b.AssertFileContent("public/fr/s1/index.html", "s1 fr") // fail (file does not exist)
236 b.AssertFileContent("public/fr/s1/p3/index.html", "p3 fr")
237 }
238
239 // Issue 13993
240 func TestIssue13993(t *testing.T) {
241 t.Parallel()
242
243 files := `
244 -- hugo.toml --
245 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
246 printPathWarnings = true
247
248 defaultContentLanguage = 'en'
249 defaultContentLanguageInSubdir = true
250
251 [languages.en]
252 contentDir = "content/en"
253 weight = 1
254
255 [languages.es]
256 contentDir = "content/es"
257 weight = 2
258
259 # Default content mounts
260
261 [[module.mounts]]
262 source = "content/en"
263 target = "content"
264 [module.mounts.sites.matrix]
265 languages = "en"
266
267 [[module.mounts]]
268 source = "content/es"
269 target = "content"
270 [module.mounts.sites.matrix]
271 languages = "es"
272
273 # Populate the missing es content with en content
274
275 [[module.mounts]]
276 source = "content/en"
277 target = "content"
278 [module.mounts.sites.matrix]
279 languages = "es"
280 -- layouts/all.html --
281 {{ .Title }}
282 -- content/en/p1.md --
283 ---
284 title: p1 (en)
285 ---
286 -- content/en/p2.md --
287 ---
288 title: p2 (en)
289 ---
290 -- content/es/p1.md --
291 ---
292 title: p1 (es)
293 ---
294 `
295
296 b := Test(t, files, TestOptInfo())
297
298 b.AssertFileExists("public/en/p1/index.html", true)
299 b.AssertFileExists("public/en/p2/index.html", true)
300 b.AssertFileExists("public/es/p1/index.html", true)
301 b.AssertFileExists("public/es/p2/index.html", true)
302
303 // This assertion was changed for 0.152.0. It was no longer possible/practical to warn about duplicate content paths.
304 b.AssertLogContains("! Duplicate")
305 }