summaryrefslogtreecommitdiffstats
path: root/hugolib/pagebundler_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/pagebundler_test.go')
-rw-r--r--hugolib/pagebundler_test.go1125
1 files changed, 259 insertions, 866 deletions
diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go
index 64d329832..123d752e0 100644
--- a/hugolib/pagebundler_test.go
+++ b/hugolib/pagebundler_test.go
@@ -15,21 +15,14 @@ package hugolib
import (
"fmt"
- "io"
"os"
- "path"
"path/filepath"
- "regexp"
+ "testing"
"github.com/gohugoio/hugo/common/loggers"
- "strings"
- "testing"
-
"github.com/gohugoio/hugo/config"
- "github.com/gohugoio/hugo/hugofs/files"
-
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
@@ -44,454 +37,180 @@ import (
qt "github.com/frankban/quicktest"
)
-func TestPageBundlerSiteRegular(t *testing.T) {
- c := qt.New(t)
- baseBaseURL := "https://example.com"
-
- for _, baseURLPath := range []string{"", "/hugo"} {
- for _, canonify := range []bool{false, true} {
- for _, ugly := range []bool{false, true} {
- baseURLPathId := baseURLPath
- if baseURLPathId == "" {
- baseURLPathId = "NONE"
- }
- ugly := ugly
- canonify := canonify
- c.Run(fmt.Sprintf("ugly=%t,canonify=%t,path=%s", ugly, canonify, baseURLPathId),
- func(c *qt.C) {
- c.Parallel()
- baseURL := baseBaseURL + baseURLPath
- relURLBase := baseURLPath
- if canonify {
- relURLBase = ""
- }
- fs, cfg := newTestBundleSources(c)
- cfg.Set("baseURL", baseURL)
- cfg.Set("canonifyURLs", canonify)
- cfg.Set("defaultContentLanguageInSubdir", false)
-
- cfg.Set("permalinks", map[string]string{
- "a": ":sections/:filename",
- "b": ":year/:slug/",
- "c": ":sections/:slug",
- "/": ":filename/",
- })
-
- cfg.Set("outputFormats", map[string]any{
- "CUSTOMO": map[string]any{
- "mediaType": "text/html",
- "baseName": "cindex",
- "path": "cpath",
- "permalinkable": true,
- },
- })
-
- cfg.Set("outputs", map[string]any{
- "home": []string{"HTML", "CUSTOMO"},
- "page": []string{"HTML", "CUSTOMO"},
- "section": []string{"HTML", "CUSTOMO"},
- })
-
- cfg.Set("uglyURLs", ugly)
- configs, err := loadTestConfigFromProvider(cfg)
-
- c.Assert(err, qt.IsNil)
-
- b := newTestSitesBuilderFromDepsCfg(c, deps.DepsCfg{Fs: fs, Configs: configs}).WithNothingAdded()
-
- b.Build(BuildCfg{})
-
- s := b.H.Sites[0]
-
- c.Assert(len(s.RegularPages()), qt.Equals, 8)
-
- singlePage := s.getPage(kinds.KindPage, "a/1.md")
- c.Assert(singlePage.BundleType(), qt.Equals, files.ContentClass(""))
-
- c.Assert(singlePage, qt.Not(qt.IsNil))
- c.Assert(s.getPage("page", "a/1"), qt.Equals, singlePage)
- c.Assert(s.getPage("page", "1"), qt.Equals, singlePage)
-
- c.Assert(content(singlePage), qt.Contains, "TheContent")
-
- relFilename := func(basePath, outBase string) (string, string) {
- rel := basePath
- if ugly {
- rel = strings.TrimSuffix(basePath, "/") + ".html"
- }
-
- var filename string
- if !ugly {
- filename = path.Join(basePath, outBase)
- } else {
- filename = rel
- }
-
- rel = fmt.Sprintf("%s%s", relURLBase, rel)
-
- return rel, filename
- }
-
- // Check both output formats
- rel, filename := relFilename("/a/1/", "index.html")
- b.AssertFileContent(filepath.Join("public", filename),
- "TheContent",
- "Single RelPermalink: "+rel,
- )
-
- rel, filename = relFilename("/cpath/a/1/", "cindex.html")
-
- b.AssertFileContent(filepath.Join("public", filename),
- "TheContent",
- "Single RelPermalink: "+rel,
- )
-
- b.AssertFileContent(filepath.FromSlash("public/images/hugo-logo.png"), "content")
-
- // This should be just copied to destination.
- b.AssertFileContent(filepath.FromSlash("public/assets/pic1.png"), "content")
-
- leafBundle1 := s.getPage(kinds.KindPage, "b/my-bundle/index.md")
- c.Assert(leafBundle1, qt.Not(qt.IsNil))
- c.Assert(leafBundle1.BundleType(), qt.Equals, files.ContentClassLeaf)
- c.Assert(leafBundle1.Section(), qt.Equals, "b")
- sectionB := s.getPage(kinds.KindSection, "b")
- c.Assert(sectionB, qt.Not(qt.IsNil))
- home := s.Home()
- c.Assert(home.BundleType(), qt.Equals, files.ContentClassBranch)
-
- // This is a root bundle and should live in the "home section"
- // See https://github.com/gohugoio/hugo/issues/4332
- rootBundle := s.getPage(kinds.KindPage, "root")
- c.Assert(rootBundle, qt.Not(qt.IsNil))
- c.Assert(rootBundle.Parent().IsHome(), qt.Equals, true)
- if !ugly {
- b.AssertFileContent(filepath.FromSlash("public/root/index.html"), "Single RelPermalink: "+relURLBase+"/root/")
- b.AssertFileContent(filepath.FromSlash("public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/")
- }
-
- leafBundle2 := s.getPage(kinds.KindPage, "a/b/index.md")
- c.Assert(leafBundle2, qt.Not(qt.IsNil))
- unicodeBundle := s.getPage(kinds.KindPage, "c/bundle/index.md")
- c.Assert(unicodeBundle, qt.Not(qt.IsNil))
-
- pageResources := leafBundle1.Resources().ByType(pageResourceType)
- c.Assert(len(pageResources), qt.Equals, 2)
- firstPage := pageResources[0].(page.Page)
- secondPage := pageResources[1].(page.Page)
-
- c.Assert(firstPage.File().Filename(), qt.Equals, filepath.FromSlash("/work/base/b/my-bundle/1.md"))
- c.Assert(content(firstPage), qt.Contains, "TheContent")
- c.Assert(len(leafBundle1.Resources()), qt.Equals, 6)
-
- // Verify shortcode in bundled page
- c.Assert(content(secondPage), qt.Contains, filepath.FromSlash("MyShort in b/my-bundle/2.md"))
-
- // https://github.com/gohugoio/hugo/issues/4582
- c.Assert(firstPage.Parent(), qt.Equals, leafBundle1)
- c.Assert(secondPage.Parent(), qt.Equals, leafBundle1)
-
- c.Assert(pageResources.GetMatch("1*"), qt.Equals, firstPage)
- c.Assert(pageResources.GetMatch("2*"), qt.Equals, secondPage)
- c.Assert(pageResources.GetMatch("doesnotexist*"), qt.IsNil)
-
- imageResources := leafBundle1.Resources().ByType("image")
- c.Assert(len(imageResources), qt.Equals, 3)
-
- c.Assert(leafBundle1.OutputFormats().Get("CUSTOMO"), qt.Not(qt.IsNil))
-
- relPermalinker := func(s string) string {
- return fmt.Sprintf(s, relURLBase)
- }
-
- permalinker := func(s string) string {
- return fmt.Sprintf(s, baseURL)
- }
-
- if ugly {
- b.AssertFileContent("public/2017/pageslug.html",
- relPermalinker("Single RelPermalink: %s/2017/pageslug.html"),
- permalinker("Single Permalink: %s/2017/pageslug.html"),
- relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
- permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"))
- } else {
- b.AssertFileContent("public/2017/pageslug/index.html",
- relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
- permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"))
-
- b.AssertFileContent("public/cpath/2017/pageslug/cindex.html",
- relPermalinker("Single RelPermalink: %s/cpath/2017/pageslug/"),
- relPermalinker("Short Sunset RelPermalink: %s/cpath/2017/pageslug/sunset2.jpg"),
- relPermalinker("Sunset RelPermalink: %s/cpath/2017/pageslug/sunset1.jpg"),
- permalinker("Sunset Permalink: %s/cpath/2017/pageslug/sunset1.jpg"),
- )
- }
-
- b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/c/logo.png"), "content")
- b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug/c/logo.png"), "content")
- c.Assert(b.CheckExists("public/cpath/cpath/2017/pageslug/c/logo.png"), qt.Equals, false)
-
- // Custom media type defined in site config.
- c.Assert(len(leafBundle1.Resources().ByType("bepsays")), qt.Equals, 1)
-
- if ugly {
- b.AssertFileContent(filepath.FromSlash("public/2017/pageslug.html"),
- "TheContent",
- relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
- permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"),
- "Thumb Width: 123",
- "Thumb Name: my-sunset-1",
- relPermalinker("Short Sunset RelPermalink: %s/2017/pageslug/sunset2.jpg"),
- "Short Thumb Width: 56",
- "1: Image Title: Sunset Galore 1",
- "1: Image Params: map[myparam:My Sunny Param]",
- relPermalinker("1: Image RelPermalink: %s/2017/pageslug/sunset1.jpg"),
- "2: Image Title: Sunset Galore 2",
- "2: Image Params: map[myparam:My Sunny Param]",
- "1: Image myParam: Lower: My Sunny Param Caps: My Sunny Param",
- "0: Page Title: Bundle Galore",
- )
-
- // https://github.com/gohugoio/hugo/issues/5882
- b.AssertFileContent(
- filepath.FromSlash("public/2017/pageslug.html"), "0: Page RelPermalink: |")
-
- b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug.html"), "TheContent")
-
- // 은행
- b.AssertFileContent(filepath.FromSlash("public/c/은행/logo-은행.png"), "은행 PNG")
-
- } else {
- b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/index.html"), "TheContent")
- b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug/cindex.html"), "TheContent")
- b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/index.html"), "Single Title")
- b.AssertFileContent(filepath.FromSlash("public/root/index.html"), "Single Title")
-
- }
- })
- }
- }
- }
-}
-
-func TestPageBundlerSiteMultilingual(t *testing.T) {
+func TestPageBundlerBundleInRoot(t *testing.T) {
t.Parallel()
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ["taxonomy", "term"]
+-- content/root/index.md --
+---
+title: "Root"
+---
+-- layouts/_default/single.html --
+Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
+Tree: Section: {{ .Section }}|CurrentSection: {{ .CurrentSection.RelPermalink }}|Parent: {{ .Parent.RelPermalink }}|FirstSection: {{ .FirstSection.RelPermalink }}
+`
+ b := Test(t, files)
- for _, ugly := range []bool{false, true} {
- ugly := ugly
- t.Run(fmt.Sprintf("ugly=%t", ugly),
- func(t *testing.T) {
- t.Parallel()
- c := qt.New(t)
- fs, cfg := newTestBundleSourcesMultilingual(t)
- cfg.Set("uglyURLs", ugly)
- configs, err := loadTestConfigFromProvider(cfg)
- c.Assert(err, qt.IsNil)
-
- b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Configs: configs}).WithNothingAdded()
- b.Build(BuildCfg{})
-
- sites := b.H
-
- c.Assert(len(sites.Sites), qt.Equals, 2)
-
- s := sites.Sites[0]
-
- c.Assert(len(s.RegularPages()), qt.Equals, 8)
- c.Assert(len(s.Pages()), qt.Equals, 16)
- // dumpPages(s.AllPages()...)
-
- c.Assert(len(s.AllPages()), qt.Equals, 31)
-
- bundleWithSubPath := s.getPage(kinds.KindPage, "lb/index")
- c.Assert(bundleWithSubPath, qt.Not(qt.IsNil))
-
- // See https://github.com/gohugoio/hugo/issues/4312
- // Before that issue:
- // A bundle in a/b/index.en.md
- // a/b/index.en.md => OK
- // a/b/index => OK
- // index.en.md => ambiguous, but OK.
- // With bundles, the file name has little meaning, the folder it lives in does. So this should also work:
- // a/b
- // and probably also just b (aka "my-bundle")
- // These may also be translated, so we also need to test that.
- // "bf", "my-bf-bundle", "index.md + nn
- bfBundle := s.getPage(kinds.KindPage, "bf/my-bf-bundle/index")
- c.Assert(bfBundle, qt.Not(qt.IsNil))
- c.Assert(bfBundle.Language().Lang, qt.Equals, "en")
- c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle/index.md"), qt.Equals, bfBundle)
- c.Assert(s.getPage(kinds.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundle)
- c.Assert(s.getPage(kinds.KindPage, "my-bf-bundle"), qt.Equals, bfBundle)
-
- nnSite := sites.Sites[1]
- c.Assert(len(nnSite.RegularPages()), qt.Equals, 7)
-
- bfBundleNN := nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle/index")
- c.Assert(bfBundleNN, qt.Not(qt.IsNil))
- c.Assert(bfBundleNN.Language().Lang, qt.Equals, "nn")
- c.Assert(nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle/index.nn.md"), qt.Equals, bfBundleNN)
- c.Assert(nnSite.getPage(kinds.KindPage, "bf/my-bf-bundle"), qt.Equals, bfBundleNN)
- c.Assert(nnSite.getPage(kinds.KindPage, "my-bf-bundle"), qt.Equals, bfBundleNN)
-
- // See https://github.com/gohugoio/hugo/issues/4295
- // Every resource should have its Name prefixed with its base folder.
- cBundleResources := bundleWithSubPath.Resources().Match("c/**")
- c.Assert(len(cBundleResources), qt.Equals, 4)
- bundlePage := bundleWithSubPath.Resources().GetMatch("c/page*")
- c.Assert(bundlePage, qt.Not(qt.IsNil))
-
- bcBundleNN, _ := nnSite.getPageNew(nil, "bc")
- c.Assert(bcBundleNN, qt.Not(qt.IsNil))
- bcBundleEN, _ := s.getPageNew(nil, "bc")
- c.Assert(bcBundleNN.Language().Lang, qt.Equals, "nn")
- c.Assert(bcBundleEN.Language().Lang, qt.Equals, "en")
- c.Assert(len(bcBundleNN.Resources()), qt.Equals, 3)
- c.Assert(len(bcBundleEN.Resources()), qt.Equals, 3)
- b.AssertFileContent("public/en/bc/data1.json", "data1")
- b.AssertFileContent("public/en/bc/data2.json", "data2")
- b.AssertFileContent("public/en/bc/logo-bc.png", "logo")
- b.AssertFileContent("public/nn/bc/data1.nn.json", "data1.nn")
- b.AssertFileContent("public/nn/bc/data2.json", "data2")
- b.AssertFileContent("public/nn/bc/logo-bc.png", "logo")
- })
- }
+ b.AssertFileContent("public/root/index.html",
+ "Basic: Root|page|leaf|/root/|",
+ "Tree: Section: |CurrentSection: /|Parent: /|FirstSection: /",
+ )
}
-func TestMultilingualDisableLanguage(t *testing.T) {
+func TestPageBundlerShortcodeInBundledPage(t *testing.T) {
t.Parallel()
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ["taxonomy", "term"]
+-- content/section/mybundle/index.md --
+---
+title: "Mybundle"
+---
+-- content/section/mybundle/p1.md --
+---
+title: "P1"
+---
- c := qt.New(t)
- fs, cfg := newTestBundleSourcesMultilingual(t)
- cfg.Set("disableLanguages", []string{"nn"})
- configs, err := loadTestConfigFromProvider(cfg)
- c.Assert(err, qt.IsNil)
+P1 content.
- b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Configs: configs}).WithNothingAdded()
- b.Build(BuildCfg{})
- sites := b.H
+{{< myShort >}}
- c.Assert(len(sites.Sites), qt.Equals, 1)
+-- layouts/_default/single.html --
+Bundled page: {{ .RelPermalink}}|{{ with .Resources.Get "p1.md" }}Title: {{ .Title }}|Content: {{ .Content }}{{ end }}|
+-- layouts/shortcodes/myShort.html --
+MyShort.
- s := sites.Sites[0]
+`
+ b := Test(t, files)
- c.Assert(len(s.RegularPages()), qt.Equals, 8)
- c.Assert(len(s.Pages()), qt.Equals, 16)
- // No nn pages
- c.Assert(len(s.AllPages()), qt.Equals, 16)
- s.pageMap.withEveryBundlePage(func(p *pageState) bool {
- c.Assert(p.Language().Lang != "nn", qt.Equals, true)
- return false
- })
+ b.AssertFileContent("public/section/mybundle/index.html",
+ "Bundled page: /section/mybundle/|Title: P1|Content: <p>P1 content.</p>\nMyShort.",
+ )
}
-func TestPageBundlerSiteWitSymbolicLinksInContent(t *testing.T) {
- skipSymlink(t)
-
- wd, _ := os.Getwd()
- defer func() {
- os.Chdir(wd)
- }()
-
- c := qt.New(t)
-
- // We need to use the OS fs for this.
- workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugosym")
- c.Assert(err, qt.IsNil)
- cfg := config.New()
- cfg.Set("workingDir", workingDir)
- cfg.Set("publishDir", "public")
- fs := hugofs.NewFromOld(hugofs.Os, cfg)
-
- contentDirName := "content"
-
- contentDir := filepath.Join(workingDir, contentDirName)
- c.Assert(os.MkdirAll(filepath.Join(contentDir, "a"), 0777), qt.IsNil)
-
- for i := 1; i <= 3; i++ {
- c.Assert(os.MkdirAll(filepath.Join(workingDir, fmt.Sprintf("symcontent%d", i)), 0777), qt.IsNil)
- }
-
- c.Assert(os.MkdirAll(filepath.Join(workingDir, "symcontent2", "a1"), 0777), qt.IsNil)
-
- // Symlinked sections inside content.
- os.Chdir(contentDir)
- for i := 1; i <= 3; i++ {
- c.Assert(os.Symlink(filepath.FromSlash(fmt.Sprintf(("../symcontent%d"), i)), fmt.Sprintf("symbolic%d", i)), qt.IsNil)
- }
-
- c.Assert(os.Chdir(filepath.Join(contentDir, "a")), qt.IsNil)
-
- // Create a symlink to one single content file
- c.Assert(os.Symlink(filepath.FromSlash("../../symcontent2/a1/page.md"), "page_s.md"), qt.IsNil)
-
- c.Assert(os.Chdir(filepath.FromSlash("../../symcontent3")), qt.IsNil)
+func TestPageBundlerResourceMultipleOutputFormatsWithDifferentPaths(t *testing.T) {
+ t.Parallel()
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ["taxonomy", "term"]
+[outputformats]
+[outputformats.cpath]
+mediaType = "text/html"
+path = "cpath"
+-- content/section/mybundle/index.md --
+---
+title: "My Bundle"
+outputs: ["html", "cpath"]
+---
+-- content/section/mybundle/hello.txt --
+Hello.
+-- content/section/mybundle/p1.md --
+---
+title: "P1"
+---
+P1.
+
+{{< hello >}}
+
+-- layouts/shortcodes/hello.html --
+Hello HTML.
+-- layouts/_default/single.html --
+Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
+Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
+-- layouts/shortcodes/hello.cpath --
+Hello CPATH.
+-- layouts/_default/single.cpath --
+Basic: {{ .Title }}|{{ .Kind }}|{{ .BundleType }}|{{ .RelPermalink }}|
+Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
+`
- // Create a circular symlink. Will print some warnings.
- c.Assert(os.Symlink(filepath.Join("..", contentDirName), filepath.FromSlash("circus")), qt.IsNil)
+ b := Test(t, files)
- c.Assert(os.Chdir(workingDir), qt.IsNil)
+ b.AssertFileContent("public/section/mybundle/index.html",
+ "Basic: My Bundle|page|leaf|/section/mybundle/|",
+ "Resources: RelPermalink: |Content: <p>P1.</p>\nHello HTML.\n|RelPermalink: /section/mybundle/hello.txt|Content: Hello.||",
+ )
- defer clean()
+ 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.||")
+}
- cfg.Set("workingDir", workingDir)
- cfg.Set("contentDir", contentDirName)
- cfg.Set("baseURL", "https://example.com")
- configs, err := loadTestConfigFromProvider(cfg)
- c.Assert(err, qt.IsNil)
+func TestPageBundlerMultilingualTextResource(t *testing.T) {
+ t.Parallel()
- layout := `{{ .Title }}|{{ .Content }}`
- pageContent := `---
-slug: %s
-date: 2017-10-09
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ["taxonomy", "term"]
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+weight = 1
+[languages.nn]
+weight = 2
+-- content/mybundle/index.md --
+---
+title: "My Bundle"
+---
+-- content/mybundle/index.nn.md --
+---
+title: "My Bundle NN"
---
+-- content/mybundle/f1.txt --
+F1
+-- content/mybundle/f2.txt --
+F2
+-- content/mybundle/f2.nn.txt --
+F2 nn.
+-- layouts/_default/single.html --
+{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}|
+Resources: {{ range .Resources }}RelPermalink: {{ .RelPermalink }}|Content: {{ .Content }}|{{ end }}|
-TheContent.
`
+ b := Test(t, files)
- b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{
- Fs: fs,
- Configs: configs,
- })
-
- b.WithTemplates(
- "_default/single.html", layout,
- "_default/list.html", layout,
- )
-
- b.WithContent(
- "a/regular.md", fmt.Sprintf(pageContent, "a1"),
- )
+ b.AssertFileContent("public/en/mybundle/index.html", "My Bundle|/en/mybundle/|en|\nResources: RelPermalink: /en/mybundle/f1.txt|Content: F1|RelPermalink: /en/mybundle/f2.txt|Content: F2||")
+ b.AssertFileContent("public/nn/mybundle/index.html", "My Bundle NN|/nn/mybundle/|nn|\nResources: RelPermalink: /en/mybundle/f1.txt|Content: F1|RelPermalink: /nn/mybundle/f2.nn.txt|Content: F2 nn.||")
+}
- b.WithSourceFile(
- "symcontent1/s1.md", fmt.Sprintf(pageContent, "s1"),
- "symcontent1/s2.md", fmt.Sprintf(pageContent, "s2"),
- // Regular files inside symlinked folder.
- "symcontent1/s1.md", fmt.Sprintf(pageContent, "s1"),
- "symcontent1/s2.md", fmt.Sprintf(pageContent, "s2"),
-
- // A bundle
- "symcontent2/a1/index.md", fmt.Sprintf(pageContent, ""),
- "symcontent2/a1/page.md", fmt.Sprintf(pageContent, "page"),
- "symcontent2/a1/logo.png", "image",
-
- // Assets
- "symcontent3/s1.png", "image",
- "symcontent3/s2.png", "image",
- )
+func TestMultilingualDisableLanguage(t *testing.T) {
+ t.Parallel()
- b.Build(BuildCfg{})
- s := b.H.Sites[0]
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableKinds = ["taxonomy", "term"]
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+disableLanguages = ["nn"]
+[languages]
+[languages.en]
+weight = 1
+[languages.nn]
+weight = 2
+-- content/p1.md --
+---
+title: "P1"
+---
+P1
+-- content/p1.nn.md --
+---
+title: "P1nn"
+---
+P1nn
+-- layouts/_default/single.html --
+{{ .Title }}|{{ .Content }}|{{ .Lang }}|
- c.Assert(len(s.RegularPages()), qt.Equals, 7)
- a1Bundle := s.getPage(kinds.KindPage, "symbolic2/a1/index.md")
- c.Assert(a1Bundle, qt.Not(qt.IsNil))
- c.Assert(len(a1Bundle.Resources()), qt.Equals, 2)
- c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1)
+`
+ b := Test(t, files)
- b.AssertFileContent(filepath.FromSlash("public/a/page/index.html"), "TheContent")
- b.AssertFileContent(filepath.FromSlash("public/symbolic1/s1/index.html"), "TheContent")
- b.AssertFileContent(filepath.FromSlash("public/symbolic2/a1/index.html"), "TheContent")
+ b.AssertFileContent("public/en/p1/index.html", "P1|<p>P1</p>\n|en|")
+ b.AssertFileExists("public/public/nn/p1/index.html", false)
+ b.Assert(len(b.H.Sites), qt.Equals, 1)
}
func TestPageBundlerHeadless(t *testing.T) {
@@ -544,10 +263,10 @@ HEADLESS {{< myShort >}}
c.Assert(len(s.RegularPages()), qt.Equals, 1)
- regular := s.getPage(kinds.KindPage, "a/index")
+ regular := s.getPageOldVersion(kinds.KindPage, "a/index")
c.Assert(regular.RelPermalink(), qt.Equals, "/s1/")
- headless := s.getPage(kinds.KindPage, "b/index")
+ headless := s.getPageOldVersion(kinds.KindPage, "b/index")
c.Assert(headless, qt.Not(qt.IsNil))
c.Assert(headless.Title(), qt.Equals, "Headless Bundle in Topless Bar")
c.Assert(headless.RelPermalink(), qt.Equals, "")
@@ -576,6 +295,7 @@ HEADLESS {{< myShort >}}
// No headless bundles here, please.
// https://github.com/gohugoio/hugo/issues/6492
c.Assert(s.RegularPages(), qt.HasLen, 1)
+ c.Assert(s.Pages(), qt.HasLen, 4)
c.Assert(s.home.RegularPages(), qt.HasLen, 1)
c.Assert(s.home.Pages(), qt.HasLen, 1)
}
@@ -686,7 +406,6 @@ Single content.
b.Build(BuildCfg{})
b.AssertFileContent("public/nn/mybundle/data.yaml", "data nn")
- b.AssertFileContent("public/nn/mybundle/forms.yaml", "forms en")
b.AssertFileContent("public/mybundle/data.yaml", "data en")
b.AssertFileContent("public/mybundle/forms.yaml", "forms en")
@@ -701,293 +420,113 @@ Single content.
b.AssertFileContent("public/section-not-bundle/single/index.html", "Section Single", "|<p>Single content.</p>")
}
-func newTestBundleSources(t testing.TB) (*hugofs.Fs, config.Provider) {
- cfg, fs := newTestCfgBasic()
- c := qt.New(t)
-
- workDir := "/work"
- cfg.Set("workingDir", workDir)
- cfg.Set("contentDir", "base")
- cfg.Set("baseURL", "https://example.com")
- cfg.Set("mediaTypes", map[string]any{
- "bepsays/bep": map[string]any{
- "suffixes": []string{"bep"},
- },
- })
-
- pageContent := `---
-title: "Bundle Galore"
-slug: pageslug
-date: 2017-10-09
----
-
-TheContent.
-`
-
- pageContentShortcode := `---
-title: "Bundle Galore"
-slug: pageslug
-date: 2017-10-09
----
-
-TheContent.
-
-{{< myShort >}}
-`
-
- pageWithImageShortcodeAndResourceMetadataContent := `---
-title: "Bundle Galore"
-slug: pageslug
-date: 2017-10-09
-resources:
-- src: "*.jpg"
- name: "my-sunset-:counter"
- title: "Sunset Galore :counter"
- params:
- myParam: "My Sunny Param"
----
-
-TheContent.
-
-{{< myShort >}}
-`
-
- pageContentNoSlug := `---
-title: "Bundle Galore #2"
-date: 2017-10-09
----
-
-TheContent.
-`
-
- singleLayout := `
-Single Title: {{ .Title }}
-Single RelPermalink: {{ .RelPermalink }}
-Single Permalink: {{ .Permalink }}
-Content: {{ .Content }}
-{{ $sunset := .Resources.GetMatch "my-sunset-1*" }}
-{{ with $sunset }}
-Sunset RelPermalink: {{ .RelPermalink }}
-Sunset Permalink: {{ .Permalink }}
-{{ $thumb := .Fill "123x123" }}
-Thumb Width: {{ $thumb.Width }}
-Thumb Name: {{ $thumb.Name }}
-Thumb Title: {{ $thumb.Title }}
-Thumb RelPermalink: {{ $thumb.RelPermalink }}
-{{ end }}
-{{ $types := slice "image" "page" }}
-{{ range $types }}
-{{ $typeTitle := . | title }}
-{{ range $i, $e := $.Resources.ByType . }}
-{{ $i }}: {{ $typeTitle }} Title: {{ .Title }}
-{{ $i }}: {{ $typeTitle }} Name: {{ .Name }}
-{{ $i }}: {{ $typeTitle }} RelPermalink: {{ .RelPermalink }}|
-{{ $i }}: {{ $typeTitle }} Params: {{ printf "%v" .Params }}
-{{ $i }}: {{ $typeTitle }} myParam: Lower: {{ .Params.myparam }} Caps: {{ .Params.MYPARAM }}
-{{ end }}
-{{ end }}
-`
+func TestBundledResourcesMultilingualDuplicateResourceFiles(t *testing.T) {
+ t.Parallel()
- myShort := `
-MyShort in {{ .Page.File.Path }}:
-{{ $sunset := .Page.Resources.GetMatch "my-sunset-2*" }}
-{{ with $sunset }}
-Short Sunset RelPermalink: {{ .RelPermalink }}
-{{ $thumb := .Fill "56x56" }}
-Short Thumb Width: {{ $thumb.Width }}
-{{ end }}
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com/"
+[markup]
+[markup.goldmark]
+duplicateResourceFiles = true
+[languages]
+[languages.en]
+weight = 1
+[languages.en.permalinks]
+"/" = "/enpages/:slug/"
+[languages.nn]
+weight = 2
+[languages.nn.permalinks]
+"/" = "/nnpages/:slug/"
+-- content/mybundle/index.md --
+---
+title: "My Bundle"
+---
+{{< getresource "f1.txt" >}}
+{{< getresource "f2.txt" >}}
+-- content/mybundle/index.nn.md --
+---
+title: "My Bundle NN"
+---
+{{< getresource "f1.txt" >}}
+f2.nn.txt is the original name.
+{{< getresource "f2.nn.txt" >}}
+{{< getresource "f2.txt" >}}
+{{< getresource "sub/f3.txt" >}}
+-- content/mybundle/f1.txt --
+F1 en.
+-- content/mybundle/sub/f3.txt --
+F1 en.
+-- content/mybundle/f2.txt --
+F2 en.
+-- content/mybundle/f2.nn.txt --
+F2 nn.
+-- layouts/shortcodes/getresource.html --
+{{ $r := .Page.Resources.Get (.Get 0)}}
+Resource: {{ (.Get 0) }}|{{ with $r }}{{ .RelPermalink }}|{{ .Content }}|{{ else }}Not found.{{ end}}
+-- layouts/_default/single.html --
+{{ .Title }}|{{ .RelPermalink }}|{{ .Lang }}|{{ .Content }}|
`
-
- listLayout := `{{ .Title }}|{{ .Content }}`
-
- writeSource(t, fs, filepath.Join(workDir, "layouts", "_default", "single.html"), singleLayout)
- writeSource(t, fs, filepath.Join(workDir, "layouts", "_default", "list.html"), listLayout)
- writeSource(t, fs, filepath.Join(workDir, "layouts", "shortcodes", "myShort.html"), myShort)
- writeSource(t, fs, filepath.Join(workDir, "layouts", "shortcodes", "myShort.customo"), myShort)
-
- writeSource(t, fs, filepath.Join(workDir, "base", "_index.md"), pageContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "_1.md"), pageContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "_1.png"), pageContent)
-
- writeSource(t, fs, filepath.Join(workDir, "base", "images", "hugo-logo.png"), "content")
- writeSource(t, fs, filepath.Join(workDir, "base", "a", "2.md"), pageContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "a", "1.md"), pageContent)
-
- writeSource(t, fs, filepath.Join(workDir, "base", "a", "b", "index.md"), pageContentNoSlug)
- writeSource(t, fs, filepath.Join(workDir, "base", "a", "b", "ab1.md"), pageContentNoSlug)
-
- // Mostly plain static assets in a folder with a page in a sub folder thrown in.
- writeSource(t, fs, filepath.Join(workDir, "base", "assets", "pic1.png"), "content")
- writeSource(t, fs, filepath.Join(workDir, "base", "assets", "pic2.png"), "content")
- writeSource(t, fs, filepath.Join(workDir, "base", "assets", "pages", "mypage.md"), pageContent)
-
- // Bundle
- writeSource(t, fs, filepath.Join(workDir, "base", "b", "my-bundle", "index.md"), pageWithImageShortcodeAndResourceMetadataContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "b", "my-bundle", "1.md"), pageContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "b", "my-bundle", "2.md"), pageContentShortcode)
- writeSource(t, fs, filepath.Join(workDir, "base", "b", "my-bundle", "custom-mime.bep"), "bepsays")
- writeSource(t, fs, filepath.Join(workDir, "base", "b", "my-bundle", "c", "logo.png"), "content")
-
- // Bundle with 은행 slug
- // See https://github.com/gohugoio/hugo/issues/4241
- writeSource(t, fs, filepath.Join(workDir, "base", "c", "bundle", "index.md"), `---
-title: "은행 은행"
-slug: 은행
-date: 2017-10-09
----
-
-Content for 은행.
+ b := Test(t, files)
+
+ // helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout)
+ b.AssertFileContent("public/nn/nnpages/my-bundle-nn/index.html", `
+My Bundle NN
+Resource: f1.txt|/nn/nnpages/my-bundle-nn/f1.txt|
+Resource: f2.txt|/nn/nnpages/my-bundle-nn/f2.nn.txt|F2 nn.|
+Resource: f2.nn.txt|/nn/nnpages/my-bundle-nn/f2.nn.txt|F2 nn.|
+Resource: sub/f3.txt|/nn/nnpages/my-bundle-nn/sub/f3.txt|F1 en.|
`)
- // Bundle in root
- writeSource(t, fs, filepath.Join(workDir, "base", "root", "index.md"), pageWithImageShortcodeAndResourceMetadataContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "root", "1.md"), pageContent)
- writeSource(t, fs, filepath.Join(workDir, "base", "root", "c", "logo.png"), "content")
+ b.AssertFileContent("public/enpages/my-bundle/f2.txt", "F2 en.")
+ b.AssertFileContent("public/nn/nnpages/my-bundle-nn/f2.nn.txt", "F2 nn")
- writeSource(t, fs, filepath.Join(workDir, "base", "c", "bundle", "logo-은행.png"), "은행 PNG")
-
- // Write a real image into one of the bundle above.
- src, err := os.Open("testdata/sunset.jpg")
- c.Assert(err, qt.IsNil)
-
- // We need 2 to test https://github.com/gohugoio/hugo/issues/4202
- out, err := fs.Source.Create(filepath.Join(workDir, "base", "b", "my-bundle", "sunset1.jpg"))
- c.Assert(err, qt.IsNil)
- out2, err := fs.Source.Create(filepath.Join(workDir, "base", "b", "my-bundle", "sunset2.jpg"))
- c.Assert(err, qt.IsNil)
-
- _, err = io.Copy(out, src)
- c.Assert(err, qt.IsNil)
- out.Close()
- src.Seek(0, 0)
- _, err = io.Copy(out2, src)
- out2.Close()
- src.Close()
- c.Assert(err, qt.IsNil)
-
- return fs, cfg
-}
-
-func newTestBundleSourcesMultilingual(t *testing.T) (*hugofs.Fs, config.Provider) {
- cfg, fs := newTestCfgBasic()
-
- workDir := "/work"
- cfg.Set("workingDir", workDir)
- cfg.Set("contentDir", "base")
- cfg.Set("baseURL", "https://example.com")