| 1 |
// Copyright 2025 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 |
"fmt" |
| 18 |
"math/rand" |
| 19 |
"strings" |
| 20 |
"testing" |
| 21 |
|
| 22 |
"github.com/bep/logg" |
| 23 |
qt "github.com/frankban/quicktest" |
| 24 |
) |
| 25 |
|
| 26 |
// The most basic build test. |
| 27 |
func TestHello(t *testing.T) { |
| 28 |
files := ` |
| 29 |
-- hugo.toml -- |
| 30 |
title = "Hello" |
| 31 |
baseURL="https://example.org" |
| 32 |
disableKinds = ["term", "taxonomy", "section", "page"] |
| 33 |
-- content/p1.md -- |
| 34 |
--- |
| 35 |
title: Page |
| 36 |
--- |
| 37 |
-- layouts/home.html -- |
| 38 |
Home: {{ .Title }} |
| 39 |
` |
| 40 |
|
| 41 |
b := Test(t, files) |
| 42 |
|
| 43 |
b.Assert(b.H.Log.LoggCount(logg.LevelWarn), qt.Equals, 0) |
| 44 |
b.AssertFileContent("public/index.html", `Hello`) |
| 45 |
} |
| 46 |
|
| 47 |
func TestSmoke202509(t *testing.T) { |
| 48 |
t.Parallel() |
| 49 |
|
| 50 |
// Test variants: |
| 51 |
// Site with two languages, one with home page content and one without. |
| 52 |
// A common translated page bundle but with different dates. |
| 53 |
// A text resource in one of the languages. |
| 54 |
// Date aggregation. |
| 55 |
// A content resource in one of the languages. |
| 56 |
// Basic shortcode usage with templates in both languages. |
| 57 |
// Test Rotate the language dimension. |
| 58 |
// The same content page mounted for all languages. |
| 59 |
// RenderString with shortcode. |
| 60 |
|
| 61 |
files := ` |
| 62 |
-- hugo.toml -- |
| 63 |
baseURL = "https://example.com" |
| 64 |
defaultContentLanguage = "en" |
| 65 |
defaultContentLanguageInSubdir = true |
| 66 |
[languages.en] |
| 67 |
title = "Site title en" |
| 68 |
weight = 200 |
| 69 |
[languages.nn] |
| 70 |
title = "Site title nn" |
| 71 |
weight = 100 |
| 72 |
[[module.mounts]] |
| 73 |
source = 'content/en' |
| 74 |
target = 'content' |
| 75 |
[module.mounts.sites.matrix] |
| 76 |
languages = 'en' |
| 77 |
[[module.mounts]] |
| 78 |
source = 'content/nn' |
| 79 |
target = 'content' |
| 80 |
[module.mounts.sites.matrix] |
| 81 |
languages = 'nn' |
| 82 |
[[module.mounts]] |
| 83 |
source = 'content/all' |
| 84 |
target = 'content' |
| 85 |
[module.mounts.sites.matrix] |
| 86 |
languages = ["**"] |
| 87 |
-- content/en/_index.md -- |
| 88 |
--- |
| 89 |
title: "Home in English" |
| 90 |
--- |
| 91 |
Home Content. |
| 92 |
-- content/en/mysection/p1/mytext.txt -- |
| 93 |
This is a text resource in English. |
| 94 |
-- content/en/mysection/p1/mypage.md -- |
| 95 |
--- |
| 96 |
title: "mypage en" |
| 97 |
--- |
| 98 |
mypage en content. |
| 99 |
-- content/en/mysection/p1/index.md -- |
| 100 |
--- |
| 101 |
title: "p1 en" |
| 102 |
date: 2023-10-01 |
| 103 |
--- |
| 104 |
Content p1 en. |
| 105 |
|
| 106 |
{{< myshortcode >}} |
| 107 |
-- content/nn/mysection/p1/index.md -- |
| 108 |
--- |
| 109 |
title: "p1 nn" |
| 110 |
date: 2024-10-01 |
| 111 |
--- |
| 112 |
Content p1 nn. |
| 113 |
|
| 114 |
{{< myshortcode >}} |
| 115 |
-- content/all/mysection/p2/index.md -- |
| 116 |
--- |
| 117 |
title: "p2 all" |
| 118 |
date: 2022-10-01 |
| 119 |
--- |
| 120 |
Content p2 all. |
| 121 |
|
| 122 |
{{< myshortcode >}} |
| 123 |
-- layouts/all.html -- |
| 124 |
All. {{ .Title }}|Lastmod: {{ .Lastmod.Format "2006-01-02" }}| |
| 125 |
Kind: {{ .Kind }}| |
| 126 |
Content: {{ .Content }}| |
| 127 |
CurrentSection: {{ .CurrentSection.PathInfo.Path }}| |
| 128 |
Parent: {{ with .Parent }}{{ .RelPermalink }}{{ end }}| |
| 129 |
Home: {{ .Site.Home.Title }}| |
| 130 |
Rotate(language): {{ range .Rotate "language" }}{{ .Lang }}|{{ .Title }}|{{ end }}| |
| 131 |
mytext.txt: {{ with .Resources.GetMatch "**.txt" }}{{ .Content }}|{{ .RelPermalink }}{{ end }}| |
| 132 |
mypage.md: {{ with .Resources.GetMatch "**.md" }}{{ .Content }}|{{ .RelPermalink }}{{ end }}| |
| 133 |
RenderString with shortcode: {{ .RenderString "{{< myshortcode >}}" }}| |
| 134 |
-- layouts/_shortcodes/myshortcode.html -- |
| 135 |
myshortcode.html |
| 136 |
-- layouts/_shortcodes/myshortcode.en.html -- |
| 137 |
myshortcode.en.html |
| 138 |
` |
| 139 |
|
| 140 |
b := Test(t, files) |
| 141 |
|
| 142 |
b.AssertFileContent("public/en/index.html", |
| 143 |
"All. Home in English|", // from content file. |
| 144 |
"Kind: home|", |
| 145 |
"Lastmod: 2023-10-01", |
| 146 |
"RenderString with shortcode: myshortcode.en.html", |
| 147 |
"Parent: |", |
| 148 |
) |
| 149 |
b.AssertFileContent("public/nn/index.html", |
| 150 |
"Site title nn|", // from project config. |
| 151 |
"Lastmod: 2024-10-01", |
| 152 |
"RenderString with shortcode: myshortcode.html", |
| 153 |
) |
| 154 |
|
| 155 |
b.AssertFileContent("public/nn/mysection/p1/index.html", |
| 156 |
"p1 nn|Lastmod: 2024-10-01|\nRotate(language): nn|p1 nn|en|p1 en||", |
| 157 |
"mytext.txt: This is a text resource in English.|/en/mysection/p1/mytext.txt|", |
| 158 |
"Content p1 nn.", |
| 159 |
"mypage.md: |", |
| 160 |
"myshortcode.html", |
| 161 |
) |
| 162 |
|
| 163 |
b.AssertFileContent("public/en/mysection/p1/index.html", |
| 164 |
"p1 en|Lastmod: 2023-10-01|\nRotate(language): nn|p1 nn|en|p1 en||", |
| 165 |
"mytext.txt: This is a text resource in English.|/en/mysection/p1/mytext.txt|", |
| 166 |
"mypage.md: <p>mypage en content.</p>", |
| 167 |
"Content p1 en.", |
| 168 |
"myshortcode.en.html", |
| 169 |
"RenderString with shortcode: myshortcode.en.html", |
| 170 |
) |
| 171 |
|
| 172 |
b.AssertFileContent("public/nn/mysection/p2/index.html", |
| 173 |
"myshortcode.html", |
| 174 |
"RenderString with shortcode: myshortcode.html", |
| 175 |
) |
| 176 |
|
| 177 |
b.AssertFileContent("public/en/mysection/p2/index.html", |
| 178 |
"myshortcode.en.html", |
| 179 |
"RenderString with shortcode: myshortcode.en.html", |
| 180 |
) |
| 181 |
} |
| 182 |
|
| 183 |
func TestSmokeTaxonomies202509(t *testing.T) { |
| 184 |
t.Parallel() |
| 185 |
|
| 186 |
files := ` |
| 187 |
-- hugo.toml -- |
| 188 |
disableKinds = ["rss", "sitemap", "robotsTXT"] |
| 189 |
baseURL = "https://example.com" |
| 190 |
defaultContentLanguage = "en" |
| 191 |
defaultContentLanguageInSubdir = true |
| 192 |
[taxonomies] |
| 193 |
category = "categories" |
| 194 |
tag = "tags" |
| 195 |
[languages.en] |
| 196 |
title = "Site title en" |
| 197 |
weight = 200 |
| 198 |
[languages.nn] |
| 199 |
title = "Site title nn" |
| 200 |
weight = 100 |
| 201 |
[languages.nn.taxonomies] |
| 202 |
tag = "tags" |
| 203 |
foo = "foos" |
| 204 |
[module] |
| 205 |
[[module.mounts]] |
| 206 |
source = 'content/en' |
| 207 |
target = 'content' |
| 208 |
[module.mounts.sites.matrix] |
| 209 |
languages = 'en' |
| 210 |
[[module.mounts]] |
| 211 |
source = 'content/nn' |
| 212 |
target = 'content' |
| 213 |
[module.mounts.sites.matrix] |
| 214 |
languages = 'nn' |
| 215 |
-- content/en/p1.md -- |
| 216 |
--- |
| 217 |
title: "p1 en" |
| 218 |
date: 2023-10-01 |
| 219 |
tags: ["tag1", "tag2"] |
| 220 |
categories: ["cat1"] |
| 221 |
foos: ["foo2"] |
| 222 |
--- |
| 223 |
Content p1 en. |
| 224 |
-- content/nn/p1.md -- |
| 225 |
--- |
| 226 |
title: "p1 nn" |
| 227 |
date: 2024-10-01 |
| 228 |
tags: ["tag1", "tag3"] |
| 229 |
categories: ["cat1", "cat2"] |
| 230 |
foos: ["foo1"] |
| 231 |
--- |
| 232 |
-- layouts/all.html -- |
| 233 |
All. {{ .Title }}|{{ .Kind }}| |
| 234 |
GetTerms tags: {{ range .GetTerms "tags" }}{{ .Name }}|{{ end }}$ |
| 235 |
GetTerms categories: {{ range .GetTerms "categories" }}{{ .Name }}|{{ end }}$ |
| 236 |
GetTerms foos: {{ range .GetTerms "foos" }}{{ .Name }}|{{ end }}$ |
| 237 |
` |
| 238 |
|
| 239 |
b := Test(t, files) |
| 240 |
|
| 241 |
b.AssertFileContent("public/en/p1/index.html", "p1 en", "GetTerms tags: tag1|tag2|$", "GetTerms categories: cat1|$", "GetTerms foos: $") |
| 242 |
b.AssertFileContent("public/nn/p1/index.html", "p1 nn", "GetTerms tags: tag1|tag3|$", "GetTerms categories: $", "GetTerms foos: foo1|$") |
| 243 |
|
| 244 |
b.AssertFileContent("public/en/tags/index.html", "All. Tags|taxonomy|") |
| 245 |
b.AssertFileContent("public/nn/tags/tag1/index.html", "All. Tag1|term|") |
| 246 |
b.AssertFileContent("public/en/tags/tag1/index.html", "All. Tag1|term|") |
| 247 |
} |
| 248 |
|
| 249 |
func TestSmokeEdits202509(t *testing.T) { |
| 250 |
t.Parallel() |
| 251 |
|
| 252 |
files := ` |
| 253 |
-- hugo.toml -- |
| 254 |
baseURL = "https://example.com" |
| 255 |
disableKinds = ["term", "taxonomy"] |
| 256 |
disableLiveReload = true |
| 257 |
defaultContentLanguage = "en" |
| 258 |
defaultContentLanguageInSubdir = true |
| 259 |
[languages.en] |
| 260 |
title = "Site title en" |
| 261 |
weight = 200 |
| 262 |
[languages.nn] |
| 263 |
title = "Site title nn" |
| 264 |
weight = 100 |
| 265 |
[module] |
| 266 |
[[module.mounts]] |
| 267 |
source = 'content/en' |
| 268 |
target = 'content' |
| 269 |
[module.mounts.sites.matrix] |
| 270 |
languages = ['en'] |
| 271 |
[[module.mounts]] |
| 272 |
source = 'content/nn' |
| 273 |
target = 'content' |
| 274 |
[module.mounts.sites.matrix] |
| 275 |
languages = ['nn'] |
| 276 |
-- content/en/p1/index.md -- |
| 277 |
--- |
| 278 |
title: "p1 en" |
| 279 |
date: 2023-10-01 |
| 280 |
--- |
| 281 |
Content p1 en. |
| 282 |
-- content/nn/p1/index.md -- |
| 283 |
--- |
| 284 |
title: "p1 nn" |
| 285 |
date: 2024-10-01 |
| 286 |
--- |
| 287 |
Content p1 nn. |
| 288 |
-- layouts/all.html -- |
| 289 |
All. {{ .Title }}|Lastmod: {{ .Lastmod.Format "2006-01-02" }}|Content: {{ .Content }}| |
| 290 |
|
| 291 |
` |
| 292 |
|
| 293 |
b := TestRunning(t, files) |
| 294 |
|
| 295 |
// b.AssertPublishDir("sDF") |
| 296 |
b.AssertFileContent("public/en/p1/index.html", "All. p1 en|") |
| 297 |
b.AssertFileContent("public/nn/p1/index.html", "All. p1 nn|") |
| 298 |
b.EditFileReplaceAll("public/en/p1/index.html", "p1 en", "p1 en edited").Build() |
| 299 |
b.AssertFileContent("public/en/p1/index.html", "All. p1 en edited") |
| 300 |
b.EditFileReplaceAll("public/nn/p1/index.html", "p1 nn", "p1 nn|").Build() |
| 301 |
} |
| 302 |
|
| 303 |
func TestSmokeOutputFormats(t *testing.T) { |
| 304 |
t.Parallel() |
| 305 |
|
| 306 |
files := ` |
| 307 |
-- hugo.toml -- |
| 308 |
baseURL = "https://example.com/" |
| 309 |
defaultContentLanguage = "en" |
| 310 |
disableKinds = ["term", "taxonomy", "robotsTXT", "sitemap"] |
| 311 |
[outputs] |
| 312 |
home = ["html", "rss"] |
| 313 |
section = ["html", "rss"] |
| 314 |
page = ["html"] |
| 315 |
-- content/p1.md -- |
| 316 |
--- |
| 317 |
title: Page |
| 318 |
--- |
| 319 |
Page. |
| 320 |
|
| 321 |
-- layouts/list.html -- |
| 322 |
List: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$ |
| 323 |
-- layouts/list.xml -- |
| 324 |
List xml: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$ |
| 325 |
-- layouts/single.html -- |
| 326 |
Single: {{ .Title }}|{{ .RelPermalink}}|{{ range .OutputFormats }}{{ .Name }}: {{ .RelPermalink }}|{{ end }}$ |
| 327 |
|
| 328 |
` |
| 329 |
|
| 330 |
for range 2 { |
| 331 |
b := Test(t, files) |
| 332 |
b.AssertFileContent("public/index.html", `List: |/|html: /|rss: /index.xml|$`) |
| 333 |
b.AssertFileContent("public/index.xml", `List xml: |/|html: /|rss: /index.xml|$`) |
| 334 |
b.AssertFileContent("public/p1/index.html", `Single: Page|/p1/|html: /p1/|$`) |
| 335 |
b.AssertFileExists("public/p1/index.xml", false) |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
func TestSmoke(t *testing.T) { |
| 340 |
t.Parallel() |
| 341 |
|
| 342 |
// Basic test cases. |
| 343 |
// OK translations |
| 344 |
// OK page collections |
| 345 |
// OK next, prev in section |
| 346 |
// OK GetPage |
| 347 |
// OK Pagination |
| 348 |
// OK RenderString with shortcode |
| 349 |
// OK cascade |
| 350 |
// OK site last mod, section last mod. |
| 351 |
// OK main sections |
| 352 |
// OK taxonomies |
| 353 |
// OK GetTerms |
| 354 |
// OK Resource page |
| 355 |
// OK Resource txt |
| 356 |
|
| 357 |
const files = ` |
| 358 |
-- hugo.toml -- |
| 359 |
baseURL = "https://example.com" |
| 360 |
title = "Smoke Site" |
| 361 |
rssLimit = 3 |
| 362 |
defaultContentLanguage = "en" |
| 363 |
defaultContentLanguageInSubdir = true |
| 364 |
enableRobotsTXT = true |
| 365 |
|
| 366 |
[pagination] |
| 367 |
pagerSize = 1 |
| 368 |
|
| 369 |
[taxonomies] |
| 370 |
category = 'categories' |
| 371 |
tag = 'tags' |
| 372 |
|
| 373 |
[languages] |
| 374 |
[languages.en] |
| 375 |
weight = 1 |
| 376 |
title = "In English" |
| 377 |
[languages.no] |
| 378 |
weight = 2 |
| 379 |
title = "På norsk" |
| 380 |
|
| 381 |
[params] |
| 382 |
hugo = "Rules!" |
| 383 |
|
| 384 |
[outputs] |
| 385 |
home = ["html", "json", "rss"] |
| 386 |
-- layouts/home.html -- |
| 387 |
Home: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|HTML |
| 388 |
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }} - {{ end }}| |
| 389 |
Site last mod: {{ site.Lastmod.Format "2006-02-01" }}| |
| 390 |
Home last mod: {{ .Lastmod.Format "2006-02-01" }}| |
| 391 |
Len Translations: {{ len .Translations }}| |
| 392 |
Len home.RegularPagesRecursive: {{ len .RegularPagesRecursive }}| |
| 393 |
RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .RelPermalink }}|{{ end }}@ |
| 394 |
Len site.RegularPages: {{ len site.RegularPages }}| |
| 395 |
Len site.Pages: {{ len site.Pages }}| |
| 396 |
Len site.AllPages: {{ len site.AllPages }}| |
| 397 |
GetPage: {{ with .Site.GetPage "posts/p1" }}{{ .RelPermalink }}|{{ .Title }}{{ end }}| |
| 398 |
RenderString with shortcode: {{ .RenderString "{{% hello %}}" }}| |
| 399 |
Paginate: {{ .Paginator.PageNumber }}/{{ .Paginator.TotalPages }}| |
| 400 |
-- layouts/index.json -- |
| 401 |
Home:{{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|JSON |
| 402 |
-- layouts/list.html -- |
| 403 |
List: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}| |
| 404 |
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }} - {{ end }} |
| 405 |
Pages Length: {{ len .Pages }} |
| 406 |
RegularPages Length: {{ len .RegularPages }} |
| 407 |
RegularPagesRecursive Length: {{ len .RegularPagesRecursive }} |
| 408 |
List last mod: {{ .Lastmod.Format "2006-02-01" }} |
| 409 |
Background: {{ .Params.background }}| |
| 410 |
Kind: {{ .Kind }} |
| 411 |
Type: {{ .Type }} |
| 412 |
Paginate: {{ .Paginator.PageNumber }}/{{ .Paginator.TotalPages }}| |
| 413 |
-- layouts/single.html -- |
| 414 |
Single: {{ .Lang}}|{{ .Kind }}|{{ .RelPermalink }}|{{ .Title }}|{{ .Content }}|Len Resources: {{ len .Resources }}|Background: {{ .Params.background }}| |
| 415 |
Resources: {{ range .Resources }}{{ .ResourceType }}|{{ .RelPermalink }}|{{ .MediaType }}|{{ .Params }} - {{ end }} |
| 416 |
{{ $textResource := .Resources.GetMatch "**.txt" }} |
| 417 |
{{ with $textResource }} |
| 418 |
Icon: {{ .Params.icon }}| |
| 419 |
{{ $textResourceFingerprinted := . | fingerprint }} |
| 420 |
Icon fingerprinted: {{ with $textResourceFingerprinted }}{{ .Params.icon }}|{{ .RelPermalink }}{{ end }}| |
| 421 |
{{ end }} |
| 422 |
NextInSection: {{ with .NextInSection }}{{ .RelPermalink }}|{{ .Title }}{{ end }}| |
| 423 |
PrevInSection: {{ with .PrevInSection }}{{ .RelPermalink }}|{{ .Title }}{{ end }}| |
| 424 |
GetTerms: {{ range .GetTerms "tags" }}name: {{ .Name }}, title: {{ .Title }}|{{ end }} |
| 425 |
-- layouts/_shortcodes/hello.html -- |
| 426 |
Hello. |
| 427 |
-- content/_index.md -- |
| 428 |
--- |
| 429 |
title: Home in English |
| 430 |
--- |
| 431 |
Home Content. |
| 432 |
-- content/_index.no.md -- |
| 433 |
--- |
| 434 |
title: Hjem |
| 435 |
cascade: |
| 436 |
- target: |
| 437 |
kind: page |
| 438 |
path: /posts/** |
| 439 |
background: post.jpg |
| 440 |
- target: |
| 441 |
kind: term |
| 442 |
background: term.jpg |
| 443 |
--- |
| 444 |
Hjem Innhold. |
| 445 |
-- content/posts/f1.txt -- |
| 446 |
posts f1 text. |
| 447 |
-- content/posts/sub/f1.txt -- |
| 448 |
posts sub f1 text. |
| 449 |
-- content/posts/p1/index.md -- |
| 450 |
+++ |
| 451 |
title = "Post 1" |
| 452 |
lastMod = "2001-01-01" |
| 453 |
tags = ["tag1"] |
| 454 |
[[resources]] |
| 455 |
src = '**' |
| 456 |
[resources.params] |
| 457 |
icon = 'enicon' |
| 458 |
+++ |
| 459 |
Content 1. |
| 460 |
-- content/posts/p1/index.no.md -- |
| 461 |
+++ |
| 462 |
title = "Post 1 no" |
| 463 |
lastMod = "2002-02-02" |
| 464 |
tags = ["tag1", "tag2"] |
| 465 |
[[resources]] |
| 466 |
src = '**' |
| 467 |
[resources.params] |
| 468 |
icon = 'noicon' |
| 469 |
+++ |
| 470 |
Content 1 no. |
| 471 |
-- content/posts/_index.md -- |
| 472 |
--- |
| 473 |
title: Posts |
| 474 |
--- |
| 475 |
-- content/posts/p1/f1.txt -- |
| 476 |
posts p1 f1 text. |
| 477 |
-- content/posts/p1/sub/ps1.md -- |
| 478 |
--- |
| 479 |
title: Post Sub 1 |
| 480 |
--- |
| 481 |
Content Sub 1. |
| 482 |
-- content/posts/p2.md -- |
| 483 |
--- |
| 484 |
title: Post 2 |
| 485 |
tags: ["tag1", "tag3"] |
| 486 |
--- |
| 487 |
Content 2. |
| 488 |
-- content/posts/p2.no.md -- |
| 489 |
--- |
| 490 |
title: Post 2 No |
| 491 |
--- |
| 492 |
Content 2 No. |
| 493 |
-- content/tags/_index.md -- |
| 494 |
--- |
| 495 |
title: Tags |
| 496 |
--- |
| 497 |
Content Tags. |
| 498 |
-- content/tags/tag1/_index.md -- |
| 499 |
--- |
| 500 |
title: Tag 1 |
| 501 |
--- |
| 502 |
Content Tag 1. |
| 503 |
|
| 504 |
|
| 505 |
` |
| 506 |
|
| 507 |
b := Test(t, files, TestOptOsFs()) |
| 508 |
|
| 509 |
b.AssertFileContent("public/en/index.html", |
| 510 |
"Home: en|home|/en/|Home in English|<p>Home Content.</p>\n|HTML", |
| 511 |
"Site last mod: 2001-01-01", |
| 512 |
"Home last mod: 2001-01-01", |
| 513 |
"Translations: 1|", |
| 514 |
"Len home.RegularPagesRecursive: 2|", |
| 515 |
"Len site.RegularPages: 2|", |
| 516 |
"Len site.Pages: 8|", |
| 517 |
"Len site.AllPages: 16|", |
| 518 |
"GetPage: /en/posts/p1/|Post 1|", |
| 519 |
"RenderString with shortcode: Hello.|", |
| 520 |
"Paginate: 1/2|", |
| 521 |
) |
| 522 |
b.AssertFileContent("public/en/page/2/index.html", "Paginate: 2/2|") |
| 523 |
|
| 524 |
b.AssertFileContent("public/no/index.html", |
| 525 |
"Home: no|home|/no/|Hjem|<p>Hjem Innhold.</p>\n|HTML", |
| 526 |
"Site last mod: 2002-02-02", |
| 527 |
"Home last mod: 2002-02-02", |
| 528 |
"Translations: 1", |
| 529 |
"GetPage: /no/posts/p1/|Post 1 no|", |
| 530 |
) |
| 531 |
|
| 532 |
b.AssertFileContent("public/en/index.json", "Home:en|home|/en/|Home in English|<p>Home Content.</p>\n|JSON") |
| 533 |
b.AssertFileContent("public/no/index.json", "Home:no|home|/no/|Hjem|<p>Hjem Innhold.</p>\n|JSON") |
| 534 |
|
| 535 |
b.AssertFileContent("public/en/posts/p1/index.html", |
| 536 |
"Single: en|page|/en/posts/p1/|Post 1|<p>Content 1.</p>\n|Len Resources: 2|", |
| 537 |
"Resources: text|/en/posts/p1/f1.txt|text/plain|map[icon:enicon] - page||application/octet-stream|map[draft:false iscjklanguage:false title:Post Sub 1] -", |
| 538 |
"Icon: enicon", |
| 539 |
"Icon fingerprinted: enicon|/en/posts/p1/f1.e5746577af5cbfc4f34c558051b7955a9a5a795a84f1c6ab0609cb3473a924cb.txt|", |
| 540 |
"NextInSection: |\nPrevInSection: /en/posts/p2/|Post 2|", |
| 541 |
"GetTerms: name: tag1, title: Tag 1|", |
| 542 |
) |
| 543 |
|
| 544 |
b.AssertFileContent("public/no/posts/p1/index.html", |
| 545 |
"Resources: 1", |
| 546 |
"Resources: text|/en/posts/p1/f1.txt|text/plain|map[icon:noicon] -", |
| 547 |
"Icon: noicon", |
| 548 |
"Icon fingerprinted: noicon|/en/posts/p1/f1.e5746577af5cbfc4f34c558051b7955a9a5a795a84f1c6ab0609cb3473a924cb.txt|", |
| 549 |
"Background: post.jpg", |
| 550 |
"NextInSection: |\nPrevInSection: /no/posts/p2/|Post 2 No|", |
| 551 |
) |
| 552 |
|
| 553 |
b.AssertFileContent("public/en/posts/index.html", |
| 554 |
"List: en|section|/en/posts/|Posts||Len Resources: 2|", |
| 555 |
"Resources: text|/en/posts/f1.txt|text/plain - text|/en/posts/sub/f1.txt|text/plain -", |
| 556 |
"List last mod: 2001-01-01", |
| 557 |
) |
| 558 |
|
| 559 |
b.AssertFileContent("public/no/posts/index.html", |
| 560 |
"List last mod: 2002-02-02", |
| 561 |
) |
| 562 |
|
| 563 |
b.AssertFileContent("public/en/posts/p2/index.html", "Single: en|page|/en/posts/p2/|Post 2|<p>Content 2.</p>\n|", |
| 564 |
"|Len Resources: 0", |
| 565 |
"GetTerms: name: tag1, title: Tag 1|name: tag3, title: Tag3|", |
| 566 |
) |
| 567 |
b.AssertFileContent("public/no/posts/p2/index.html", "Single: no|page|/no/posts/p2/|Post 2 No|<p>Content 2 No.</p>\n|") |
| 568 |
|
| 569 |
b.AssertFileContent("public/no/categories/index.html", |
| 570 |
"Kind: taxonomy", |
| 571 |
"Type: categories", |
| 572 |
) |
| 573 |
b.AssertFileContent("public/no/tags/index.html", |
| 574 |
"Kind: taxonomy", |
| 575 |
"Type: tags", |
| 576 |
) |
| 577 |
|
| 578 |
b.AssertFileContent("public/no/tags/tag1/index.html", |
| 579 |
"Background: term.jpg", |
| 580 |
"Kind: term", |
| 581 |
"Type: tags", |
| 582 |
"Paginate: 1/1|", |
| 583 |
) |
| 584 |
|
| 585 |
b.AssertFileContent("public/en/tags/tag1/index.html", |
| 586 |
"Kind: term", |
| 587 |
"Type: tags", |
| 588 |
"Paginate: 1/2|", |
| 589 |
) |
| 590 |
} |
| 591 |
|
| 592 |
// Basic tests that verifies that the different file systems work as expected. |
| 593 |
func TestSmokeFilesystems(t *testing.T) { |
| 594 |
t.Parallel() |
| 595 |
|
| 596 |
files := ` |
| 597 |
-- hugo.toml -- |
| 598 |
baseURL = "https://example.com" |
| 599 |
defaultContentLanguage = "en" |
| 600 |
defaultContentLanguageInSubdir = true |
| 601 |
[languages] |
| 602 |
[languages.en] |
| 603 |
title = "In English" |
| 604 |
[languages.nn] |
| 605 |
title = "På nynorsk" |
| 606 |
[module] |
| 607 |
[[module.mounts]] |
| 608 |
source = "i18n" |
| 609 |
target = "i18n" |
| 610 |
[[module.mounts]] |
| 611 |
source = "data" |
| 612 |
target = "data" |
| 613 |
[[module.mounts]] |
| 614 |
source = "content/en" |
| 615 |
target = "content" |
| 616 |
[module.mounts.sites.matrix] |
| 617 |
languages = "en" |
| 618 |
[[module.mounts]] |
| 619 |
source = "content/nn" |
| 620 |
target = "content" |
| 621 |
[module.mounts.sites.matrix] |
| 622 |
languages = "nn" |
| 623 |
[[module.imports]] |
| 624 |
path = "mytheme" |
| 625 |
-- layouts/home.html -- |
| 626 |
i18n s1: {{ i18n "s1" }}| |
| 627 |
i18n s2: {{ i18n "s2" }}| |
| 628 |
data s1: {{ hugo.Data.d1.s1 }}| |
| 629 |
data s2: {{ hugo.Data.d1.s2 }}| |
| 630 |
title: {{ .Title }}| |
| 631 |
-- themes/mytheme/hugo.toml -- |
| 632 |
[[module.mounts]] |
| 633 |
source = "i18n" |
| 634 |
target = "i18n" |
| 635 |
[[module.mounts]] |
| 636 |
source = "data" |
| 637 |
target = "data" |
| 638 |
# i18n files both project and theme. |
| 639 |
-- i18n/en.toml -- |
| 640 |
[s1] |
| 641 |
other = 's1project' |
| 642 |
-- i18n/nn.toml -- |
| 643 |
[s1] |
| 644 |
other = 's1prosjekt' |
| 645 |
-- themes/mytheme/i18n/en.toml -- |
| 646 |
[s1] |
| 647 |
other = 's1theme' |
| 648 |
[s2] |
| 649 |
other = 's2theme' |
| 650 |
# data files both project and theme. |
| 651 |
-- data/d1.yaml -- |
| 652 |
s1: s1project |
| 653 |
-- themes/mytheme/data/d1.yaml -- |
| 654 |
s1: s1theme |
| 655 |
s2: s2theme |
| 656 |
# Content |
| 657 |
-- content/en/_index.md -- |
| 658 |
--- |
| 659 |
title: "Home" |
| 660 |
--- |
| 661 |
-- content/nn/_index.md -- |
| 662 |
--- |
| 663 |
title: "Heim" |
| 664 |
--- |
| 665 |
|
| 666 |
` |
| 667 |
b := Test(t, files) |
| 668 |
|
| 669 |
b.AssertFileContent("public/en/index.html", |
| 670 |
"i18n s1: s1project", "i18n s2: s2theme", |
| 671 |
"data s1: s1project", "data s2: s2theme", |
| 672 |
"title: Home", |
| 673 |
) |
| 674 |
|
| 675 |
b.AssertFileContent("public/nn/index.html", |
| 676 |
"i18n s1: s1prosjekt", "i18n s2: s2theme", |
| 677 |
"data s1: s1project", "data s2: s2theme", |
| 678 |
"title: Heim", |
| 679 |
) |
| 680 |
} |
| 681 |
|
| 682 |
// https://github.com/golang/go/issues/30286 |
| 683 |
func TestDataRace(t *testing.T) { |
| 684 |
var filesBuilder strings.Builder |
| 685 |
|
| 686 |
filesBuilder.WriteString(` |
| 687 |
-- hugo.toml -- |
| 688 |
baseURL = "https://example.org" |
| 689 |
defaultContentLanguage = "en" |
| 690 |
|
| 691 |
[outputs] |
| 692 |
home = ["HTML", "JSON", "CSV", "RSS"] |
| 693 |
page = ["HTML", "JSON"] |
| 694 |
|
| 695 |
[mediaTypes] |
| 696 |
[mediaTypes."application/json"] |
| 697 |
suffixes = ["json"] |
| 698 |
[mediaTypes."text/csv"] |
| 699 |
suffixes = ["csv"] |
| 700 |
|
| 701 |
[outputFormats.JSON] |
| 702 |
mediaType = "application/json" |
| 703 |
isPlainText = true |
| 704 |
isHTML = false |
| 705 |
|
| 706 |
[outputFormats.CSV] |
| 707 |
mediaType = "text/csv" |
| 708 |
isPlainText = true |
| 709 |
isHTML = false |
| 710 |
|
| 711 |
-- layouts/single.html -- |
| 712 |
HTML Single: {{ .Data.Pages }} |
| 713 |
-- layouts/list.html -- |
| 714 |
HTML List: {{ .Data.Pages }} |
| 715 |
-- content/_index.md -- |
| 716 |
--- |
| 717 |
title: "The Home" |
| 718 |
outputs: ["HTML", "JSON", "CSV", "RSS"] |
| 719 |
--- |
| 720 |
The content. |
| 721 |
`) |
| 722 |
|
| 723 |
const pageContent = ` |
| 724 |
--- |
| 725 |
title: "The Page" |
| 726 |
outputs: ["HTML", "JSON"] |
| 727 |
--- |
| 728 |
The content. |
| 729 |
` |
| 730 |
|
| 731 |
for i := 1; i <= 50; i++ { |
| 732 |
filesBuilder.WriteString(fmt.Sprintf("\n-- content/blog/page%d.md --\n%s", i, pageContent)) |
| 733 |
} |
| 734 |
|
| 735 |
files := filesBuilder.String() |
| 736 |
|
| 737 |
_ = Test(t, files) |
| 738 |
|
| 739 |
// Assertions can be added here if needed, but the original test only builds. |
| 740 |
// The primary purpose of TestDataRace is to check for race conditions during the build process. |
| 741 |
// If the build completes without race detector errors, the test passes. |
| 742 |
} |
| 743 |
|
| 744 |
// This is just a test to verify that BenchmarkBaseline is working as intended. |
| 745 |
func TestBenchmarkBaseline(t *testing.T) { |
| 746 |
b := Test(t, benchmarkBaselineFiles(true)) |
| 747 |
|
| 748 |
b.Assert(len(b.H.Sites), qt.Equals, 4) |
| 749 |
b.Assert(len(b.H.Sites[0].RegularPages()), qt.Equals, 161) |
| 750 |
b.Assert(len(b.H.Sites[0].Pages()), qt.Equals, 197) |
| 751 |
b.Assert(len(b.H.Sites[2].RegularPages()), qt.Equals, 158) |
| 752 |
b.Assert(len(b.H.Sites[2].Pages()), qt.Equals, 194) |
| 753 |
} |
| 754 |
|
| 755 |
func BenchmarkBaseline(b *testing.B) { |
| 756 |
cfg := IntegrationTestConfig{ |
| 757 |
T: b, |
| 758 |
TxtarString: benchmarkBaselineFiles(false), |
| 759 |
} |
| 760 |
|
| 761 |
for b.Loop() { |
| 762 |
b.StopTimer() |
| 763 |
builder := NewIntegrationTestBuilder(cfg) |
| 764 |
b.StartTimer() |
| 765 |
builder.Build() |
| 766 |
} |
| 767 |
} |
| 768 |
|
| 769 |
func benchmarkBaselineFiles(leafBundles bool) string { |
| 770 |
rnd := rand.New(rand.NewSource(32)) |
| 771 |
|
| 772 |
var files strings.Builder |
| 773 |
files.WriteString(` |
| 774 |
-- hugo.toml -- |
| 775 |
baseURL = "https://example.com" |
| 776 |
defaultContentLanguage = 'en' |
| 777 |
|
| 778 |
[module] |
| 779 |
[[module.mounts]] |
| 780 |
source = 'content/en' |
| 781 |
target = 'content/en' |
| 782 |
[module.mounts.sites.matrix] |
| 783 |
languages = 'en' |
| 784 |
[[module.mounts]] |
| 785 |
source = 'content/nn' |
| 786 |
target = 'content/nn' |
| 787 |
[module.mounts.sites.matrix] |
| 788 |
languages = 'nn' |
| 789 |
[[module.mounts]] |
| 790 |
source = 'content/no' |
| 791 |
target = 'content/no' |
| 792 |
[module.mounts.sites.matrix] |
| 793 |
languages = 'no' |
| 794 |
[[module.mounts]] |
| 795 |
source = 'content/sv' |
| 796 |
target = 'content/sv' |
| 797 |
[module.mounts.sites.matrix] |
| 798 |
languages = 'sv' |
| 799 |
[[module.mounts]] |
| 800 |
source = 'layouts' |
| 801 |
target = 'layouts' |
| 802 |
|
| 803 |
[languages] |
| 804 |
[languages.en] |
| 805 |
title = "English" |
| 806 |
weight = 1 |
| 807 |
[languages.nn] |
| 808 |
title = "Nynorsk" |
| 809 |
weight = 2 |
| 810 |
[languages.no] |
| 811 |
title = "Norsk" |
| 812 |
weight = 3 |
| 813 |
[languages.sv] |
| 814 |
title = "Svenska" |
| 815 |
weight = 4 |
| 816 |
-- layouts/list.html -- |
| 817 |
{{ .Title }} |
| 818 |
{{ .Content }} |
| 819 |
-- layouts/single.html -- |
| 820 |
{{ .Title }} |
| 821 |
{{ .Content }} |
| 822 |
-- layouts/_shortcodes/myshort.html -- |
| 823 |
{{ .Inner }} |
| 824 |
`) |
| 825 |
|
| 826 |
contentTemplate := ` |
| 827 |
--- |
| 828 |
title: "Page %d" |
| 829 |
date: "2018-01-01" |
| 830 |
weight: %d |
| 831 |
--- |
| 832 |
|
| 833 |
## Heading 1 |
| 834 |
|
| 835 |
Duis nisi reprehenderit nisi cupidatat cillum aliquip ea id eu esse commodo et. |
| 836 |
|
| 837 |
## Heading 2 |
| 838 |
|
| 839 |
Aliqua labore enim et sint anim amet excepteur ea dolore. |
| 840 |
|
| 841 |
{{< myshort >}} |
| 842 |
Hello, World! |
| 843 |
{{< /myshort >}} |
| 844 |
|
| 845 |
Aliqua labore enim et sint anim amet excepteur ea dolore. |
| 846 |
|
| 847 |
|
| 848 |
` |
| 849 |
|
| 850 |
for _, lang := range []string{"en", "nn", "no", "sv"} { |
| 851 |
files.WriteString(fmt.Sprintf("\n-- content/%s/_index.md --\n"+contentTemplate, lang, 1, 1, 1)) |
| 852 |
for i, root := range []string{"", "foo", "bar", "baz"} { |
| 853 |
for j, section := range []string{"posts", "posts/funny", "posts/science", "posts/politics", "posts/world", "posts/technology", "posts/world/news", "posts/world/news/europe"} { |
| 854 |
n := i + j + 1 |
| 855 |
files.WriteString(fmt.Sprintf("\n-- content/%s/%s/%s/_index.md --\n"+contentTemplate, lang, root, section, n, n, n)) |
| 856 |
for k := 1; k < rnd.Intn(30)+1; k++ { |
| 857 |
n := n + k |
| 858 |
ns := fmt.Sprintf("%d", n) |
| 859 |
if leafBundles { |
| 860 |
ns = fmt.Sprintf("%d/index", n) |
| 861 |
} |
| 862 |
file := fmt.Sprintf("\n-- content/%s/%s/%s/p%s.md --\n"+contentTemplate, lang, root, section, ns, n, n) |
| 863 |
files.WriteString(file) |
| 864 |
} |
| 865 |
} |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
return files.String() |
| 870 |
} |