| 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 |
"testing" |
| 18 |
|
| 19 |
qt "github.com/frankban/quicktest" |
| 20 |
) |
| 21 |
|
| 22 |
func TestPageBundlerBasic(t *testing.T) { |
| 23 |
files := ` |
| 24 |
-- hugo.toml -- |
| 25 |
[security] |
| 26 |
allowContent = ['.*'] |
| 27 |
-- content/mybundle/index.md -- |
| 28 |
--- |
| 29 |
title: "My Bundle" |
| 30 |
--- |
| 31 |
-- content/mybundle/p1.md -- |
| 32 |
--- |
| 33 |
title: "P1" |
| 34 |
--- |
| 35 |
-- content/mybundle/p1.html -- |
| 36 |
--- |
| 37 |
title: "P1 HTML" |
| 38 |
--- |
| 39 |
-- content/mybundle/data.txt -- |
| 40 |
Data txt. |
| 41 |
-- content/mybundle/sub/data.txt -- |
| 42 |
Data sub txt. |
| 43 |
-- content/mybundle/sub/index.md -- |
| 44 |
-- content/mysection/_index.md -- |
| 45 |
--- |
| 46 |
title: "My Section" |
| 47 |
--- |
| 48 |
-- content/mysection/data.txt -- |
| 49 |
Data section txt. |
| 50 |
-- layouts/all.html -- |
| 51 |
All. {{ .Title }}|{{ .RelPermalink }}|{{ .Kind }}|{{ .BundleType }}| |
| 52 |
` |
| 53 |
|
| 54 |
b := Test(t, files) |
| 55 |
|
| 56 |
b.AssertFileContent("public/mybundle/index.html", "My Bundle|/mybundle/|page|leaf|") |
| 57 |
} |
| 58 |
|
| 59 |
func TestPageBundlerBundleInRoot(t *testing.T) { |
| 60 |
t.Parallel() |
| 61 |
files := ` |
| 62 |
-- hugo.toml -- |
| 63 |
baseURL = "https://example.com" |
| 64 |
disableKinds = ["taxonomy", "term"] |
| 65 |
-- content/root/index.md -- |
| 66 |
--- |
| 67 |
title: "Root" |
| 68 |
--- |
| 69 |
-- layouts/single.html -- |
| 70 |
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}| |
| 71 |
Tree: Section: {{ .Section }}|CurrentSection: {{ .CurrentSection.RelPermalink }}|Parent: {{ .Parent.RelPermalink }}|FirstSection: {{ .FirstSection.RelPermalink }} |
| 72 |
` |
| 73 |
b := Test(t, files) |
| 74 |
|
| 75 |
b.AssertFileContent("public/root/index.html", |
| 76 |
"Basic: Root|page|leaf|/root/|", |
| 77 |
"Tree: Section: |CurrentSection: /|Parent: /|FirstSection: /", |
| 78 |
) |
| 79 |
} |
| 80 |
|
| 81 |
func TestPageBundlerShortcodeInBundledPage(t *testing.T) { |
| 82 |
t.Parallel() |
| 83 |
files := ` |
| 84 |
-- hugo.toml -- |
| 85 |
baseURL = "https://example.com" |
| 86 |
disableKinds = ["taxonomy", "term"] |
| 87 |
-- content/section/mybundle/index.md -- |
| 88 |
--- |
| 89 |
title: "Mybundle" |
| 90 |
--- |
| 91 |
-- content/section/mybundle/p1.md -- |
| 92 |
--- |
| 93 |
title: "P1" |
| 94 |
--- |
| 95 |
|
| 96 |
P1 content. |
| 97 |
|
| 98 |
{{< myShort >}} |
| 99 |
|
| 100 |
-- layouts/single.html -- |
| 101 |
Bundled page: {{ .RelPermalink}}|{{ with .Resources.Get "p1.md" }}Title: {{ .Title }}|Content: {{ .Content }}{{ end }}| |
| 102 |
-- layouts/_shortcodes/myShort.html -- |
| 103 |
MyShort. |
| 104 |
|
| 105 |
` |
| 106 |
b := Test(t, files) |
| 107 |
|
| 108 |
b.AssertFileContent("public/section/mybundle/index.html", |
| 109 |
"Bundled page: /section/mybundle/|Title: P1|Content: <p>P1 content.</p>\nMyShort.", |
| 110 |
) |
| 111 |
} |
| 112 |
|
| 113 |
func TestPageBundlerResourceMultipleOutputFormatsWithDifferentPaths(t *testing.T) { |
| 114 |
t.Parallel() |
| 115 |
files := ` |
| 116 |
-- hugo.toml -- |
| 117 |
baseURL = "https://example.com" |
| 118 |
disableKinds = ["taxonomy", "term"] |
| 119 |
[outputformats] |
| 120 |
[outputformats.cpath] |
| 121 |
mediaType = "text/html" |
| 122 |
path = "cpath" |
| 123 |
-- content/section/mybundle/index.md -- |
| 124 |
--- |
| 125 |
title: "My Bundle" |
| 126 |
outputs: ["html", "cpath"] |
| 127 |
--- |
| 128 |
-- content/section/mybundle/hello.txt -- |
| 129 |
Hello. |
| 130 |
-- content/section/mybundle/p1.md -- |
| 131 |
--- |
| 132 |
title: "P1" |
| 133 |
--- |
| 134 |
P1. |
| 135 |
|
| 136 |
{{< hello >}} |
| 137 |
|
| 138 |
-- layouts/_shortcodes/hello.html -- |
| 139 |
Hello HTML. |
| 140 |
-- layouts/single.html -- |
| 141 |
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}| |
| 142 |
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}| |
| 143 |
-- layouts/_shortcodes/hello.cpath -- |
| 144 |
Hello CPATH. |
| 145 |
-- layouts/single.cpath -- |
| 146 |
Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}| |
| 147 |
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}| |
| 148 |
` |
| 149 |
|
| 150 |
b := Test(t, files) |
| 151 |
|
| 152 |
b.AssertFileContent("public/section/mybundle/index.html", |
| 153 |
"Basic: My Bundle|page|leaf|/section/mybundle/|", |
| 154 |
"Resources: RelPermalink: |Content: <p>P1.</p>\nHello HTML.\n|RelPermalink: /section/mybundle/hello.txt|Content: Hello.||", |
| 155 |
) |
| 156 |
|
| 157 |
b.AssertFileContent("public/cpath/section/mybundle/index.html", "Basic: My Bundle|page|leaf|/section/mybundle/|\nResources: RelPermalink: |Content: <p>P1.</p>\nHello CPATH.\n|RelPermalink: /section/mybundle/hello.txt|Content: Hello.||") |
| 158 |
} |
| 159 |
|
| 160 |
func TestPageBundlerMultilingualTextResource(t *testing.T) { |
| 161 |
t.Parallel() |
| 162 |
|
| 163 |
files := ` |
| 164 |
-- hugo.toml -- |
| 165 |
baseURL = "https://example.com" |
| 166 |
disableKinds = ["taxonomy", "term"] |
| 167 |
defaultContentLanguage = "en" |
| 168 |
defaultContentLanguageInSubdir = true |
| 169 |
[languages] |
| 170 |
[languages.en] |
| 171 |
weight = 1 |
| 172 |
[languages.en.permalinks] |
| 173 |
"/" = "/enpages/:slug/" |
| 174 |
[languages.nn] |
| 175 |
weight = 2 |
| 176 |
-- content/mybundle/index.md -- |
| 177 |
--- |
| 178 |
title: "My Bundle" |
| 179 |
--- |
| 180 |
-- content/mybundle/index.nn.md -- |
| 181 |
--- |
| 182 |
title: "My Bundle NN" |
| 183 |
--- |
| 184 |
-- content/mybundle/f1.txt -- |
| 185 |
F1 |
| 186 |
-- content/mybundle/f2.txt -- |
| 187 |
F2 |
| 188 |
-- content/mybundle/f2.nn.txt -- |
| 189 |
F2 nn. |
| 190 |
-- layouts/single.html -- |
| 191 |
{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}| |
| 192 |
Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}| |
| 193 |
|
| 194 |
` |
| 195 |
b := Test(t, files) |
| 196 |
|
| 197 |
b.AssertFileContent("public/en/enpages/my-bundle/index.html", "My Bundle|/en/enpages/my-bundle/|en|\nResources: RelPermalink: /en/enpages/my-bundle/f1.txt|Content: F1|RelPermalink: /en/enpages/my-bundle/f2.txt|Content: F2||") |
| 198 |
b.AssertFileContent("public/nn/mybundle/index.html", "My Bundle NN|/nn/mybundle/|nn|\nResources: RelPermalink: /en/enpages/my-bundle/f1.txt|Content: F1|RelPermalink: /nn/mybundle/f2.nn.txt|Content: F2 nn.||") |
| 199 |
} |
| 200 |
|
| 201 |
func TestMultilingualDisableLanguage(t *testing.T) { |
| 202 |
t.Parallel() |
| 203 |
|
| 204 |
files := ` |
| 205 |
-- hugo.toml -- |
| 206 |
baseURL = "https://example.com" |
| 207 |
disableKinds = ["taxonomy", "term"] |
| 208 |
defaultContentLanguage = "en" |
| 209 |
defaultContentLanguageInSubdir = true |
| 210 |
[languages] |
| 211 |
[languages.en] |
| 212 |
weight = 1 |
| 213 |
[languages.nn] |
| 214 |
weight = 2 |
| 215 |
disabled = true |
| 216 |
-- content/mysect/_index.md -- |
| 217 |
--- |
| 218 |
title: "My Sect En" |
| 219 |
--- |
| 220 |
-- content/mysect/p1/index.md -- |
| 221 |
--- |
| 222 |
title: "P1" |
| 223 |
--- |
| 224 |
P1 |
| 225 |
-- content/mysect/_index.nn.md -- |
| 226 |
--- |
| 227 |
title: "My Sect Nn" |
| 228 |
--- |
| 229 |
-- content/mysect/p1/index.nn.md -- |
| 230 |
--- |
| 231 |
title: "P1nn" |
| 232 |
--- |
| 233 |
P1nn |
| 234 |
-- layouts/home.html -- |
| 235 |
Len RegularPages: {{ len .Site.RegularPages }}|RegularPages: {{ range site.RegularPages }}{{ .RelPermalink }}: {{ .Title }}|{{ end }}| |
| 236 |
Len Pages: {{ len .Site.Pages }}| |
| 237 |
Len Sites: {{ len hugo.Sites }}| |
| 238 |
-- layouts/single.html -- |
| 239 |
{{ .Title }}|{{ .Content }}|{{ .Lang }}| |
| 240 |
|
| 241 |
` |
| 242 |
b := Test(t, files) |
| 243 |
|
| 244 |
b.AssertFileContent("public/en/index.html", "Len RegularPages: 1|") |
| 245 |
b.AssertFileContent("public/en/mysect/p1/index.html", "P1|<p>P1</p>\n|en|") |
| 246 |
b.AssertFileExists("public/public/nn/mysect/p1/index.html", false) |
| 247 |
b.Assert(len(b.H.Sites), qt.Equals, 1) |
| 248 |
} |
| 249 |
|
| 250 |
func TestMultilingualDisableLanguageMounts(t *testing.T) { |
| 251 |
t.Parallel() |
| 252 |
|
| 253 |
files := ` |
| 254 |
-- hugo.toml -- |
| 255 |
baseURL = "https://example.com" |
| 256 |
disableKinds = ["taxonomy", "term"] |
| 257 |
defaultContentLanguage = "en" |
| 258 |
defaultContentLanguageInSubdir = true |
| 259 |
[[module.mounts]] |
| 260 |
source = 'content/nn' |
| 261 |
target = 'content' |
| 262 |
[module.mounts.sites.matrix] |
| 263 |
languages = "nn" |
| 264 |
[[module.mounts]] |
| 265 |
source = 'content/en' |
| 266 |
target = 'content' |
| 267 |
[module.mounts.sites.matrix] |
| 268 |
languages = "en" |
| 269 |
|
| 270 |
[languages] |
| 271 |
[languages.en] |
| 272 |
weight = 1 |
| 273 |
[languages.nn] |
| 274 |
weight = 2 |
| 275 |
disabled = true |
| 276 |
-- content/en/mysect/_index.md -- |
| 277 |
--- |
| 278 |
title: "My Sect En" |
| 279 |
--- |
| 280 |
-- content/en/mysect/p1/index.md -- |
| 281 |
--- |
| 282 |
title: "P1" |
| 283 |
--- |
| 284 |
P1 |
| 285 |
-- content/nn/mysect/_index.md -- |
| 286 |
--- |
| 287 |
title: "My Sect Nn" |
| 288 |
--- |
| 289 |
-- content/nn/mysect/p1/index.md -- |
| 290 |
--- |
| 291 |
title: "P1nn" |
| 292 |
--- |
| 293 |
P1nn |
| 294 |
-- layouts/home.html -- |
| 295 |
Len RegularPages: {{ len .Site.RegularPages }}|RegularPages: {{ range site.RegularPages }}{{ .RelPermalink }}: {{ .Title }}|{{ end }}| |
| 296 |
Len Pages: {{ len .Site.Pages }}| |
| 297 |
Len Sites: {{ len hugo.Sites }}| |
| 298 |
-- layouts/single.html -- |
| 299 |
{{ .Title }}|{{ .Content }}|{{ .Lang }}| |
| 300 |
|
| 301 |
` |
| 302 |
b := Test(t, files) |
| 303 |
|
| 304 |
b.AssertFileContent("public/en/index.html", "Len RegularPages: 1|") |
| 305 |
b.AssertFileContent("public/en/mysect/p1/index.html", "P1|<p>P1</p>\n|en|") |
| 306 |
b.AssertFileExists("public/public/nn/mysect/p1/index.html", false) |
| 307 |
b.Assert(len(b.H.Sites), qt.Equals, 1) |
| 308 |
} |
| 309 |
|
| 310 |
func TestPageBundlerHeadlessIssue6552(t *testing.T) { |
| 311 |
t.Parallel() |
| 312 |
|
| 313 |
files := ` |
| 314 |
-- hugo.toml -- |
| 315 |
baseURL = "http://example.com/" |
| 316 |
-- content/headless/h1/index.md -- |
| 317 |
--- |
| 318 |
title: My Headless Bundle1 |
| 319 |
headless: true |
| 320 |
--- |
| 321 |
-- content/headless/h1/p1.md -- |
| 322 |
--- |
| 323 |
title: P1 |
| 324 |
--- |
| 325 |
-- content/headless/h2/index.md -- |
| 326 |
--- |
| 327 |
title: My Headless Bundle2 |
| 328 |
headless: true |
| 329 |
--- |
| 330 |
-- layouts/home.html -- |
| 331 |
{{ $headless1 := .Site.GetPage "headless/h1" }} |
| 332 |
{{ $headless2 := .Site.GetPage "headless/h2" }} |
| 333 |
|
| 334 |
HEADLESS1: {{ $headless1.Title }}|{{ $headless1.RelPermalink }}|{{ len $headless1.Resources }}| |
| 335 |
HEADLESS2: {{ $headless2.Title }}{{ $headless2.RelPermalink }}|{{ len $headless2.Resources }}| |
| 336 |
` |
| 337 |
b := Test(t, files) |
| 338 |
|
| 339 |
b.AssertFileContent("public/index.html", ` |
| 340 |
HEADLESS1: My Headless Bundle1||1| |
| 341 |
HEADLESS2: My Headless Bundle2|0| |
| 342 |
`) |
| 343 |
} |
| 344 |
|
| 345 |
func TestMultiSiteBundles(t *testing.T) { |
| 346 |
t.Parallel() |
| 347 |
|
| 348 |
files := ` |
| 349 |
-- hugo.toml -- |
| 350 |
baseURL = "http://example.com/" |
| 351 |
defaultContentLanguage = "en" |
| 352 |
|
| 353 |
[languages] |
| 354 |
[languages.en] |
| 355 |
weight = 10 |
| 356 |
contentDir = "content/en" |
| 357 |
[languages.nn] |
| 358 |
weight = 20 |
| 359 |
contentDir = "content/nn" |
| 360 |
|
| 361 |
-- content/en/mybundle/index.md -- |
| 362 |
--- |
| 363 |
headless: true |
| 364 |
--- |
| 365 |
-- content/nn/mybundle/index.md -- |
| 366 |
--- |
| 367 |
headless: true |
| 368 |
--- |
| 369 |
-- content/en/mybundle/data.yaml -- |
| 370 |
data en |
| 371 |
-- content/en/mybundle/forms.yaml -- |
| 372 |
forms en |
| 373 |
-- content/nn/mybundle/data.yaml -- |
| 374 |
data nn |
| 375 |
-- content/en/_index.md -- |
| 376 |
--- |
| 377 |
Title: Home |
| 378 |
--- |
| 379 |
|
| 380 |
Home content. |
| 381 |
-- content/en/section-not-bundle/_index.md -- |
| 382 |
--- |
| 383 |
Title: Section Page |
| 384 |
--- |
| 385 |
|
| 386 |
Section content. |
| 387 |
-- content/en/section-not-bundle/single.md -- |
| 388 |
--- |
| 389 |
Title: Section Single |
| 390 |
Date: 2018-02-01 |
| 391 |
--- |
| 392 |
|
| 393 |
Single content. |
| 394 |
-- layouts/single.html -- |
| 395 |
{{ .Title }}|{{ .Content }} |
| 396 |
-- layouts/list.html -- |
| 397 |
{{ .Title }}|{{ .Content }} |
| 398 |
` |
| 399 |
b := Test(t, files) |
| 400 |
|
| 401 |
b.AssertFileContent("public/nn/mybundle/data.yaml", "data nn") |
| 402 |
b.AssertFileContent("public/mybundle/data.yaml", "data en") |
| 403 |
b.AssertFileContent("public/mybundle/forms.yaml", "forms en") |
| 404 |
|
| 405 |
b.AssertFileExists("public/nn/nn/mybundle/data.yaml", false) |
| 406 |
b.AssertFileExists("public/en/mybundle/data.yaml", false) |
| 407 |
|
| 408 |
homeEn := b.H.Sites[0].home |
| 409 |
b.Assert(homeEn, qt.Not(qt.IsNil)) |
| 410 |
b.Assert(homeEn.Date().Year(), qt.Equals, 2018) |
| 411 |
|
| 412 |
b.AssertFileContent("public/section-not-bundle/index.html", "Section Page|<p>Section content.</p>") |
| 413 |
b.AssertFileContent("public/section-not-bundle/single/index.html", "Section Single|<p>Single content.</p>") |
| 414 |
} |
| 415 |
|
| 416 |
func TestBundledResourcesMultilingualDuplicateResourceFiles(t *testing.T) { |
| 417 |
t.Parallel() |
| 418 |
|
| 419 |
files := ` |
| 420 |
-- hugo.toml -- |
| 421 |
baseURL = "https://example.com/" |
| 422 |
[markup] |
| 423 |
[markup.goldmark] |
| 424 |
duplicateResourceFiles = true |
| 425 |
[languages] |
| 426 |
[languages.en] |
| 427 |
weight = 1 |
| 428 |
[languages.en.permalinks] |
| 429 |
"/" = "/enpages/:slug/" |
| 430 |
[languages.nn] |
| 431 |
weight = 2 |
| 432 |
[languages.nn.permalinks] |
| 433 |
"/" = "/nnpages/:slug/" |
| 434 |
-- content/mybundle/index.md -- |
| 435 |
--- |
| 436 |
title: "My Bundle" |
| 437 |
--- |
| 438 |
{{< getresource "f1.txt" >}} |
| 439 |
{{< getresource "f2.txt" >}} |
| 440 |
-- content/mybundle/index.nn.md -- |
| 441 |
--- |
| 442 |
title: "My Bundle NN" |
| 443 |
--- |
| 444 |
{{< getresource "f1.txt" >}} |
| 445 |
f2.nn.txt is the original name. |
| 446 |
{{< getresource "f2.nn.txt" >}} |
| 447 |
{{< getresource "f2.txt" >}} |
| 448 |
{{< getresource "sub/f3.txt" >}} |
| 449 |
-- content/mybundle/f1.txt -- |
| 450 |
F1 en. |
| 451 |
-- content/mybundle/sub/f3.txt -- |
| 452 |
F1 en. |
| 453 |
-- content/mybundle/f2.txt -- |
| 454 |
F2 en. |
| 455 |
-- content/mybundle/f2.nn.txt -- |
| 456 |
F2 nn. |
| 457 |
-- layouts/_shortcodes/getresource.html -- |
| 458 |
{{ $r := .Page.Resources.Get (.Get 0)}} |
| 459 |
Resource: {{ (.Get 0) }}|{{ with $r }}{{ .RelPermalink }}|{{ .Content }}|{{ else }}Not found.{{ end}} |
| 460 |
-- layouts/single.html -- |
| 461 |
{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}|{{ .Content }}| |
| 462 |
` |
| 463 |
b := Test(t, files) |
| 464 |
|
| 465 |
// helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout) |
| 466 |
b.AssertFileContent("public/nn/nnpages/my-bundle-nn/index.html", ` |
| 467 |
My Bundle NN |
| 468 |
Resource: f1.txt|/nn/nnpages/my-bundle-nn/f1.txt| |
| 469 |
Resource: f2.txt|/nn/nnpages/my-bundle-nn/f2.nn.txt|F2 nn.| |
| 470 |
Resource: f2.nn.txt|/nn/nnpages/my-bundle-nn/f2.nn.txt|F2 nn.| |
| 471 |
Resource: sub/f3.txt|/nn/nnpages/my-bundle-nn/sub/f3.txt|F1 en.| |
| 472 |
`) |
| 473 |
|
| 474 |
b.AssertFileContent("public/enpages/my-bundle/f2.txt", "F2 en.") |
| 475 |
b.AssertFileContent("public/nn/nnpages/my-bundle-nn/f2.nn.txt", "F2 nn") |
| 476 |
|
| 477 |
b.AssertFileContent("public/enpages/my-bundle/index.html", ` |
| 478 |
Resource: f1.txt|/enpages/my-bundle/f1.txt|F1 en.| |
| 479 |
Resource: f2.txt|/enpages/my-bundle/f2.txt|F2 en.| |
| 480 |
`) |
| 481 |
b.AssertFileContent("public/enpages/my-bundle/f1.txt", "F1 en.") |
| 482 |
|
| 483 |
// Should be duplicated to the nn bundle. |
| 484 |
b.AssertFileContent("public/nn/nnpages/my-bundle-nn/f1.txt", "F1 en.") |
| 485 |
} |
| 486 |
|
| 487 |
// https://github.com/gohugoio/hugo/issues/5858 |
| 488 |
func TestBundledResourcesWhenMultipleOutputFormats(t *testing.T) { |
| 489 |
t.Parallel() |
| 490 |
|
| 491 |
files := ` |
| 492 |
-- hugo.toml -- |
| 493 |
baseURL = "https://example.org" |
| 494 |
disableKinds = ["taxonomy", "term"] |
| 495 |
disableLiveReload = true |
| 496 |
[outputs] |
| 497 |
# This looks odd, but it triggers the behavior in #5858 |
| 498 |
# The total output formats list gets sorted, so CSS before HTML. |
| 499 |
home = [ "CSS" ] |
| 500 |
-- content/mybundle/index.md -- |
| 501 |
--- |
| 502 |
title: Page |
| 503 |
--- |
| 504 |
-- content/mybundle/data.json -- |
| 505 |
MyData |
| 506 |
-- layouts/single.html -- |
| 507 |
{{ range .Resources }} |
| 508 |
{{ .ResourceType }}|{{ .Title }}| |
| 509 |
{{ end }} |
| 510 |
` |
| 511 |
|
| 512 |
b := TestRunning(t, files) |
| 513 |
|
| 514 |
b.AssertFileContent("public/mybundle/data.json", "MyData") |
| 515 |
|
| 516 |
b.EditFileReplaceAll("content/mybundle/data.json", "MyData", "My changed data").Build() |
| 517 |
|
| 518 |
b.AssertFileContent("public/mybundle/data.json", "My changed data") |
| 519 |
} |
| 520 |
|
| 521 |
// See #11663 |
| 522 |
func TestPageBundlerPartialTranslations(t *testing.T) { |
| 523 |
t.Parallel() |
| 524 |
files := ` |
| 525 |
-- hugo.toml -- |
| 526 |
baseURL = "https://example.com" |
| 527 |
disableKinds = ["taxonomy", "term"] |
| 528 |
defaultContentLanguage = "en" |
| 529 |
defaultContentLanguageInSubDir = true |
| 530 |
[languages] |
| 531 |
[languages.nn] |
| 532 |
weight = 2 |
| 533 |
[languages.en] |
| 534 |
weight = 1 |
| 535 |
-- content/section/mybundle/index.md -- |
| 536 |
--- |
| 537 |
title: "Mybundle" |
| 538 |
--- |
| 539 |
-- content/section/mybundle/bundledpage.md -- |
| 540 |
--- |
| 541 |
title: "Bundled page en" |
| 542 |
--- |
| 543 |
-- content/section/mybundle/bundledpage.nn.md -- |
| 544 |
--- |
| 545 |
title: "Bundled page nn" |
| 546 |
--- |
| 547 |
|
| 548 |
-- layouts/single.html -- |
| 549 |
Bundled page: {{ .RelPermalink}}|Len resources: {{ len .Resources }}| |
| 550 |
|
| 551 |
|
| 552 |
` |
| 553 |
b := Test(t, files) |
| 554 |
|
| 555 |
b.AssertFileContent("public/en/section/mybundle/index.html", |
| 556 |
"Bundled page: /en/section/mybundle/|Len resources: 1|", |
| 557 |
) |
| 558 |
|
| 559 |
b.AssertFileExists("public/nn/section/mybundle/index.html", false) |
| 560 |
} |
| 561 |
|
| 562 |
// #6208 |
| 563 |
func TestBundleIndexInSubFolder(t *testing.T) { |
| 564 |
t.Parallel() |
| 565 |
|
| 566 |
files := ` |
| 567 |
-- hugo.toml -- |
| 568 |
baseURL = "https://example.com" |
| 569 |
-- layouts/single.html -- |
| 570 |
{{ range .Resources }} |
| 571 |
{{ .ResourceType }}|{{ .Title }}| |
| 572 |
{{ end }} |
| 573 |
-- content/bundle/index.md -- |
| 574 |
--- |
| 575 |
title: "bundle index" |
| 576 |
--- |
| 577 |
-- content/bundle/p1.md -- |
| 578 |
--- |
| 579 |
title: "bundle p1" |
| 580 |
--- |
| 581 |
-- content/bundle/sub/p2.md -- |
| 582 |
--- |
| 583 |
title: "bundle sub p2" |
| 584 |
--- |
| 585 |
-- content/bundle/sub/index.md -- |
| 586 |
--- |
| 587 |
title: "bundle sub index" |
| 588 |
--- |
| 589 |
-- content/bundle/sub/data.json -- |
| 590 |
data |
| 591 |
` |
| 592 |
b := Test(t, files) |
| 593 |
|
| 594 |
b.AssertFileContent("public/bundle/index.html", ` |
| 595 |
application|sub/data.json| |
| 596 |
page|bundle p1| |
| 597 |
page|bundle sub index| |
| 598 |
page|bundle sub p2| |
| 599 |
`) |
| 600 |
} |
| 601 |
|
| 602 |
func TestPageBundlerHome(t *testing.T) { |
| 603 |
t.Parallel() |
| 604 |
|
| 605 |
files := ` |
| 606 |
-- hugo.toml -- |
| 607 |
baseURL = "http://example.com/" |
| 608 |
-- content/_index.md -- |
| 609 |
--- |
| 610 |
title: Home |
| 611 |
--- |
| 612 |
 |
| 613 |
-- content/data.json -- |
| 614 |
DATA |
| 615 |
-- layouts/home.html -- |
| 616 |
Title: {{ .Title }}|First Resource: {{ index .Resources 0 }}|Content: {{ .Content }} |
| 617 |
-- layouts/_markup/render-image.html -- |
| 618 |
Hook Len Page Resources {{ len .Page.Resources }} |
| 619 |
` |
| 620 |
b := Test(t, files) |
| 621 |
|
| 622 |
b.AssertFileContent("public/index.html", ` |
| 623 |
Title: Home|First Resource: data.json|Content: <p>Hook Len Page Resources 1</p> |
| 624 |
`) |
| 625 |
} |
| 626 |
|
| 627 |
func TestHTMLFilesIsue11999(t *testing.T) { |
| 628 |
t.Parallel() |
| 629 |
|
| 630 |
files := ` |
| 631 |
-- hugo.toml -- |
| 632 |
disableKinds = ["taxonomy", "term", "rss", "sitemap", "robotsTXT", "404"] |
| 633 |
[permalinks] |
| 634 |
posts = "/myposts/:slugorcontentbasename" |
| 635 |
[security] |
| 636 |
allowContent = ['.*'] |
| 637 |
-- content/posts/markdown-without-frontmatter.md -- |
| 638 |
-- content/posts/html-without-frontmatter.html -- |
| 639 |
<html>hello</html> |
| 640 |
-- content/posts/html-with-frontmatter.html -- |
| 641 |
--- |
| 642 |
title: "HTML with frontmatter" |
| 643 |
--- |
| 644 |
<html>hello</html> |
| 645 |
-- content/posts/html-with-commented-out-frontmatter.html -- |
| 646 |
<!-- |
| 647 |
--- |
| 648 |
title: "HTML with commented out frontmatter" |
| 649 |
--- |
| 650 |
--> |
| 651 |
<html>hello</html> |
| 652 |
-- content/posts/markdown-with-frontmatter.md -- |
| 653 |
--- |
| 654 |
title: "Markdown" |
| 655 |
--- |
| 656 |
-- content/posts/mybundle/index.md -- |
| 657 |
--- |
| 658 |
title: My Bundle |
| 659 |
--- |
| 660 |
-- content/posts/mybundle/data.txt -- |
| 661 |
Data.txt |
| 662 |
-- content/posts/mybundle/html-in-bundle-without-frontmatter.html -- |
| 663 |
<html>hell</html> |
| 664 |
-- content/posts/mybundle/html-in-bundle-with-frontmatter.html -- |
| 665 |
--- |
| 666 |
title: Hello |
| 667 |
--- |
| 668 |
<html>hello</html> |
| 669 |
-- content/posts/mybundle/html-in-bundle-with-commented-out-frontmatter.html -- |
| 670 |
<!-- |
| 671 |
--- |
| 672 |
title: "HTML with commented out frontmatter" |
| 673 |
--- |
| 674 |
--> |
| 675 |
<html>hello</html> |
| 676 |
-- layouts/home.html -- |
| 677 |
{{ range site.RegularPages }}{{ .RelPermalink }}|{{ end }}$ |
| 678 |
-- layouts/single.html -- |
| 679 |
{{ .Title }}|{{ .RelPermalink }}Resources: {{ range .Resources }}{{ .Name }}|{{ end }}$ |
| 680 |
|
| 681 |
` |
| 682 |
b := Test(t, files) |
| 683 |
|
| 684 |
b.AssertFileContent("public/index.html", "/myposts/html-with-commented-out-frontmatter/|/myposts/html-without-frontmatter/|/myposts/markdown-without-frontmatter/|/myposts/html-with-frontmatter/|/myposts/markdown-with-frontmatter/|/myposts/mybundle/|$") |
| 685 |
|
| 686 |
b.AssertFileContent("public/myposts/mybundle/index.html", |
| 687 |
"My Bundle|/myposts/mybundle/Resources: html-in-bundle-with-commented-out-frontmatter.html|html-in-bundle-without-frontmatter.html|html-in-bundle-with-frontmatter.html|data.txt|$") |
| 688 |
|
| 689 |
b.AssertPublishDir(` |
| 690 |
index.html |
| 691 |
myposts/html-with-commented-out-frontmatter |
| 692 |
myposts/html-with-commented-out-frontmatter/index.html |
| 693 |
myposts/html-with-frontmatter |
| 694 |
myposts/html-with-frontmatter/index.html |
| 695 |
myposts/html-without-frontmatter |
| 696 |
myposts/html-without-frontmatter/index.html |
| 697 |
myposts/markdown-with-frontmatter |
| 698 |
myposts/markdown-with-frontmatter/index.html |
| 699 |
myposts/markdown-without-frontmatter |
| 700 |
myposts/markdown-without-frontmatter/index.html |
| 701 |
myposts/mybundle/data.txt |
| 702 |
myposts/mybundle/index.html |
| 703 |
! myposts/mybundle/html-in-bundle-with-frontmatter.html |
| 704 |
`) |
| 705 |
} |
| 706 |
|
| 707 |
func TestBundleDuplicatePagesAndResources(t *testing.T) { |
| 708 |
files := ` |
| 709 |
-- hugo.toml -- |
| 710 |
baseURL = "https://example.com" |
| 711 |
disableKinds = ["taxonomy", "term"] |
| 712 |
[security] |
| 713 |
allowContent = ['.*'] |
| 714 |
-- content/mysection/mybundle/index.md -- |
| 715 |
-- content/mysection/mybundle/index.html -- |
| 716 |
-- content/mysection/mybundle/p1.md -- |
| 717 |
-- content/mysection/mybundle/p1.html -- |
| 718 |
-- content/mysection/mybundle/foo/p1.html -- |
| 719 |
-- content/mysection/mybundle/data.txt -- |
| 720 |
Data txt. |
| 721 |
-- content/mysection/mybundle/data.en.txt -- |
| 722 |
Data en txt. |
| 723 |
-- content/mysection/mybundle/data.json -- |
| 724 |
Data JSON. |
| 725 |
-- content/mysection/_index.md -- |
| 726 |
-- content/mysection/_index.html -- |
| 727 |
-- content/mysection/sectiondata.json -- |
| 728 |
Secion data JSON. |
| 729 |
-- content/mysection/sectiondata.txt -- |
| 730 |
Section data TXT. |
| 731 |
-- content/mysection/p2.md -- |
| 732 |
-- content/mysection/p2.html -- |
| 733 |
-- content/mysection/foo/p2.md -- |
| 734 |
-- layouts/single.html -- |
| 735 |
Single:{{ .Title }}|{{ .Path }}|File LogicalName: {{ with .File }}{{ .LogicalName }}{{ end }}||{{ .RelPermalink }}|{{ .Kind }}|Resources: {{ range .Resources}}{{ .Name }}: {{ .Content }}|{{ end }}$ |
| 736 |
-- layouts/list.html -- |
| 737 |
List: {{ .Title }}|{{ .Path }}|File LogicalName: {{ with .File }}{{ .LogicalName }}{{ end }}|{{ .RelPermalink }}|{{ .Kind }}|Resources: {{ range .Resources}}{{ .Name }}: {{ .Content }}|{{ end }}$ |
| 738 |
RegularPages: {{ range .RegularPages }}{{ .RelPermalink }}|File LogicalName: {{ with .File }}{{ .LogicalName }}|{{ end }}{{ end }}$ |
| 739 |
` |
| 740 |
|
| 741 |
b := Test(t, files) |
| 742 |
|
| 743 |
// Note that the sort order gives us the most specific data file for the en language (the data.en.json). |
| 744 |
b.AssertFileContent("public/mysection/mybundle/index.html", `Single:|/mysection/mybundle|File LogicalName: index.md||/mysection/mybundle/|page|Resources: data.en.txt: Data en txt.|data.json: Data JSON.|foo/p1.html: |p1.html: |p1.md: |$`) |
| 745 |
b.AssertFileContent("public/mysection/index.html", |
| 746 |
"List: |/mysection|File LogicalName: _index.md|/mysection/|section|Resources: sectiondata.json: Secion data JSON.|sectiondata.txt: Section data TXT.|$", |
| 747 |
"RegularPages: /mysection/foo/p2/|File LogicalName: p2.md|/mysection/mybundle/|File LogicalName: index.md|/mysection/p2/|File LogicalName: p2.md|$") |
| 748 |
} |
| 749 |
|
| 750 |
func TestBundleResourcesGetMatchOriginalName(t *testing.T) { |
| 751 |
files := ` |
| 752 |
-- hugo.toml -- |
| 753 |
baseURL = "https://example.com" |
| 754 |
-- content/mybundle/index.md -- |
| 755 |
-- content/mybundle/f1.en.txt -- |
| 756 |
F1. |
| 757 |
-- layouts/single.html -- |
| 758 |
GetMatch: {{ with .Resources.GetMatch "f1.en.*" }}{{ .Name }}: {{ .Content }}|{{ end }} |
| 759 |
Match: {{ range .Resources.Match "f1.En.*" }}{{ .Name }}: {{ .Content }}|{{ end }} |
| 760 |
` |
| 761 |
|
| 762 |
b := Test(t, files) |
| 763 |
|
| 764 |
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.en.txt: F1.|", "Match: f1.en.txt: F1.|") |
| 765 |
} |
| 766 |
|
| 767 |
func TestBundleResourcesWhenLanguageVariantIsDraft(t *testing.T) { |
| 768 |
files := ` |
| 769 |
-- hugo.toml -- |
| 770 |
baseURL = "https://example.com" |
| 771 |
defaultContentLanguage = "en" |
| 772 |
[languages] |
| 773 |
[languages.en] |
| 774 |
weight = 1 |
| 775 |
[languages.nn] |
| 776 |
weight = 2 |
| 777 |
-- content/mybundle/index.en.md -- |
| 778 |
-- content/mybundle/index.nn.md -- |
| 779 |
--- |
| 780 |
draft: true |
| 781 |
--- |
| 782 |
-- content/mybundle/f1.en.txt -- |
| 783 |
F1. |
| 784 |
-- layouts/single.html -- |
| 785 |
GetMatch: {{ with .Resources.GetMatch "f1.*" }}{{ .Name }}: {{ .Content }}|{{ end }}$ |
| 786 |
` |
| 787 |
|
| 788 |
b := Test(t, files) |
| 789 |
|
| 790 |
b.AssertFileContent("public/mybundle/index.html", "GetMatch: f1.en.txt: F1.|") |
| 791 |
} |
| 792 |
|
| 793 |
func TestBundleBranchIssue12320(t *testing.T) { |
| 794 |
t.Parallel() |
| 795 |
|
| 796 |
files := ` |
| 797 |
-- hugo.toml -- |
| 798 |
disableKinds = ['rss','sitemap','taxonomy','term'] |
| 799 |
defaultContentLanguage = 'en' |
| 800 |
defaultContentLanguageInSubdir = true |
| 801 |
[languages.en] |
| 802 |
baseURL = "https://en.example.org/" |
| 803 |
contentDir = "content/en" |
| 804 |
[languages.fr] |
| 805 |
baseURL = "https://fr.example.org/" |
| 806 |
contentDir = "content/fr" |
| 807 |
-- content/en/s1/p1.md -- |
| 808 |
--- |
| 809 |
title: p1 |
| 810 |
--- |
| 811 |
-- content/en/s1/p1.txt -- |
| 812 |
--- |
| 813 |
p1.txt |
| 814 |
--- |
| 815 |
-- layouts/single.html -- |
| 816 |
{{ .Title }}| |
| 817 |
-- layouts/list.html -- |
| 818 |
{{ .Title }}| |
| 819 |
` |
| 820 |
|
| 821 |
b := Test(t, files) |
| 822 |
|
| 823 |
b.AssertFileExists("public/en/s1/index.html", true) |
| 824 |
b.AssertFileExists("public/en/s1/p1/index.html", true) |
| 825 |
b.AssertFileExists("public/en/s1/p1.txt", true) |
| 826 |
|
| 827 |
b.AssertFileExists("public/fr/s1/index.html", false) |
| 828 |
b.AssertFileExists("public/fr/s1/p1/index.html", false) |
| 829 |
b.AssertFileExists("public/fr/s1/p1.txt", false) // failing test |
| 830 |
} |