diff options
Diffstat (limited to 'hugolib/hugo_sites_multihost_test.go')
-rw-r--r-- | hugolib/hugo_sites_multihost_test.go | 251 |
1 files changed, 169 insertions, 82 deletions
diff --git a/hugolib/hugo_sites_multihost_test.go b/hugolib/hugo_sites_multihost_test.go index a37310987..a9aad67b2 100644 --- a/hugolib/hugo_sites_multihost_test.go +++ b/hugolib/hugo_sites_multihost_test.go @@ -3,19 +3,15 @@ package hugolib import ( "testing" - "github.com/gohugoio/hugo/resources/kinds" - qt "github.com/frankban/quicktest" ) -func TestMultihosts(t *testing.T) { +func TestMultihost(t *testing.T) { t.Parallel() - c := qt.New(t) - - configTemplate := ` + files := ` +-- hugo.toml -- paginate = 1 -disablePathToLower = true defaultContentLanguage = "fr" defaultContentLanguageInSubdir = false staticDir = ["s1", "s2"] @@ -24,98 +20,189 @@ enableRobotsTXT = true [permalinks] other = "/somewhere/else/:filename" -[Taxonomies] +[taxonomies] tag = "tags" -[Languages] -[Languages.en] -staticDir2 = ["ens1", "ens2"] +[languages] +[languages.en] +staticDir2 = ["staticen"] baseURL = "https://example.com/docs" weight = 10 title = "In English" languageName = "English" - -[Languages.fr] -staticDir2 = ["frs1", "frs2"] +[languages.fr] +staticDir2 = ["staticfr"] baseURL = "https://example.fr" weight = 20 title = "Le Français" languageName = "Français" +-- assets/css/main.css -- +body { color: red; } +-- content/mysect/mybundle/index.md -- +--- +tags: [a, b] +title: "My Bundle fr" +--- +My Bundle +-- content/mysect/mybundle/index.en.md -- +--- +tags: [c, d] +title: "My Bundle en" +--- +My Bundle +-- content/mysect/mybundle/foo.txt -- +Foo +-- layouts/_default/list.html -- +List|{{ .Title }}|{{ .Lang }}|{{ .Permalink}}|{{ .RelPermalink }}| +-- layouts/_default/single.html -- +Single|{{ .Title }}|{{ .Lang }}|{{ .Permalink}}|{{ .RelPermalink }}| +{{ $foo := .Resources.Get "foo.txt" | fingerprint }} +Foo: {{ $foo.Permalink }}| +{{ $css := resources.Get "css/main.css" | fingerprint }} +CSS: {{ $css.Permalink }}|{{ $css.RelPermalink }}| +-- layouts/robots.txt -- +robots|{{ site.Language.Lang }} +-- layouts/404.html -- +404|{{ site.Language.Lang }} + + + +` + + b := Test(t, files) + + b.Assert(b.H.Conf.IsMultiLingual(), qt.Equals, true) + b.Assert(b.H.Conf.IsMultihost(), qt.Equals, true) + + // helpers.PrintFs(b.H.Fs.PublishDir, "", os.Stdout) -[Languages.nn] -staticDir2 = ["nns1", "nns2"] -baseURL = "https://example.no" -weight = 30 -title = "På nynorsk" -languageName = "Nynorsk" + // Check regular pages. + b.AssertFileContent("public/en/mysect/mybundle/index.html", "Single|My Bundle en|en|https://example.com/docs/mysect/mybundle/|") + b.AssertFileContent("public/fr/mysect/mybundle/index.html", "Single|My Bundle fr|fr|https://example.fr/mysect/mybundle/|") + + // Check robots.txt + b.AssertFileContent("public/en/robots.txt", "robots|en") + b.AssertFileContent("public/fr/robots.txt", "robots|fr") + + // Check sitemap.xml + b.AssertFileContent("public/en/sitemap.xml", "https://example.com/docs/mysect/mybundle/") + b.AssertFileContent("public/fr/sitemap.xml", "https://example.fr/mysect/mybundle/") + + // Check 404 + b.AssertFileContent("public/en/404.html", "404|en") + b.AssertFileContent("public/fr/404.html", "404|fr") + + // Check tags. + b.AssertFileContent("public/en/tags/d/index.html", "List|D|en|https://example.com/docs/tags/d/") + b.AssertFileContent("public/fr/tags/b/index.html", "List|B|fr|https://example.fr/tags/b/") + b.AssertFileExists("public/en/tags/b/index.html", false) + b.AssertFileExists("public/fr/tags/d/index.html", false) + + // en/mysect/mybundle/foo.txt fingerprinted + b.AssertFileContent("public/en/mysect/mybundle/foo.1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa.txt", "Foo") + b.AssertFileContent("public/en/mysect/mybundle/index.html", "Foo: https://example.com/docs/mysect/mybundle/foo.1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa.txt|") + b.AssertFileContent("public/fr/mysect/mybundle/foo.1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa.txt", "Foo") + b.AssertFileContent("public/fr/mysect/mybundle/index.html", "Foo: https://example.fr/mysect/mybundle/foo.1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d550b648afa.txt|") + + // Assets CSS fingerprinted + b.AssertFileContent("public/en/mysect/mybundle/index.html", "CSS: https://example.fr/css/main.5de625c36355cce7c1d5408826a0b21abfb49fb6c0e1f16c945a6f2aef38200c.css|") + b.AssertFileContent("public/en/css/main.5de625c36355cce7c1d5408826a0b21abfb49fb6c0e1f16c945a6f2aef38200c.css", "body { color: red; }") + b.AssertFileContent("public/fr/mysect/mybundle/index.html", "CSS: https://example.fr/css/main.5de625c36355cce7c1d5408826a0b21abfb49fb6c0e1f16c945a6f2aef38200c.css|") + b.AssertFileContent("public/fr/css/main.5de625c36355cce7c1d5408826a0b21abfb49fb6c0e1f16c945a6f2aef38200c.css", "body { color: red; }") +} + +func TestMultihostResourcePerLanguageMultihostMinify(t *testing.T) { + t.Parallel() + files := ` +-- hugo.toml -- +disableKinds = ["taxonomy", "term"] +defaultContentLanguage = "en" +defaultContentLanguageInSubDir = true +[languages] +[languages.en] +baseURL = "https://example.en" +weight = 1 +contentDir = "content/en" +[languages.fr] +baseURL = "https://example.fr" +weight = 2 +contentDir = "content/fr" +-- content/en/section/mybundle/index.md -- +--- +title: "Mybundle en" +--- +-- content/fr/section/mybundle/index.md -- +--- +title: "Mybundle fr" +--- +-- content/en/section/mybundle/styles.css -- +.body { + color: english; +} +-- content/fr/section/mybundle/styles.css -- +.body { + color: french; +} +-- layouts/_default/single.html -- +{{ $data := .Resources.GetMatch "styles*" | minify }} +{{ .Lang }}: {{ $data.Content}}|{{ $data.RelPermalink }}| ` + b := Test(t, files) + + b.AssertFileContent("public/fr/section/mybundle/index.html", + "fr: .body{color:french}|/section/mybundle/styles.min.css|", + ) + + b.AssertFileContent("public/en/section/mybundle/index.html", + "en: .body{color:english}|/section/mybundle/styles.min.css|", + ) - b := newMultiSiteTestDefaultBuilder(t).WithConfigFile("toml", configTemplate) - b.CreateSites().Build(BuildCfg{}) + b.AssertFileContent("public/en/section/mybundle/styles.min.css", ".body{color:english}") + b.AssertFileContent("public/fr/section/mybundle/styles.min.css", ".body{color:french}") +} - b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Hello") +func TestMultihostResourceOneBaseURLWithSuPath(t *testing.T) { + files := ` +-- hugo.toml -- +defaultContentLanguage = "en" +[languages] +[languages.en] +baseURL = "https://example.com/docs" +weight = 1 +contentDir = "content/en" +[languages.en.permalinks] +section = "/enpages/:slug/" +[languages.fr] +baseURL = "https://example.fr" +contentDir = "content/fr" +-- content/en/section/mybundle/index.md -- +--- +title: "Mybundle en" +--- +-- content/fr/section/mybundle/index.md -- +--- +title: "Mybundle fr" +--- +-- content/fr/section/mybundle/file1.txt -- +File 1 fr. +-- content/en/section/mybundle/file1.txt -- +File 1 en. +-- content/en/section/mybundle/file2.txt -- +File 2 en. +-- layouts/_default/single.html -- +{{ $files := .Resources.Match "file*" }} +Files: {{ range $files }}{{ .Permalink }}|{{ end }}$ - s1 := b.H.Sites[0] +` - s1h := s1.getPage(kinds.KindHome) - c.Assert(s1h.IsTranslated(), qt.Equals, true) - c.Assert(len(s1h.Translations()), qt.Equals, 2) - c.Assert(s1h.Permalink(), qt.Equals, "https://example.com/docs/") + b := Test(t, files) - // For “regular multilingual” we kept the aliases pages with url in front matter - // as a literal value that we use as is. - // There is an ambiguity in the guessing. - // For multihost, we never want any content in the root. - // - // check url in front matter: - pageWithURLInFrontMatter := s1.getPage(kinds.KindPage, "sect/doc3.en.md") - c.Assert(pageWithURLInFrontMatter, qt.Not(qt.IsNil)) - c.Assert(pageWithURLInFrontMatter.RelPermalink(), qt.Equals, "/docs/superbob/") - b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en") + b.AssertFileContent("public/en/enpages/mybundle-en/index.html", "Files: https://example.com/docs/enpages/mybundle-en/file1.txt|https://example.com/docs/enpages/mybundle-en/file2.txt|$") + b.AssertFileContent("public/fr/section/mybundle/index.html", "Files: https://example.fr/section/mybundle/file1.txt|https://example.fr/section/mybundle/file2.txt|$") - // the domain root is the language directory for each language, so the robots.txt is created in the language directories - b.AssertFileContent("public/en/robots.txt", "robots|en") - b.AssertFileContent("public/fr/robots.txt", "robots|fr") - b.AssertFileContent("public/nn/robots.txt", "robots|nn") - b.AssertFileDoesNotExist("public/robots.txt") - - // check alias: - b.AssertFileContent("public/en/al/alias1/index.html", `content="0; url=https://example.com/docs/superbob/"`) - b.AssertFileContent("public/en/al/alias2/index.html", `content="0; url=https://example.com/docs/superbob/"`) - - s2 := b.H.Sites[1] - - s2h := s2.getPage(kinds.KindHome) - c.Assert(s2h.Permalink(), qt.Equals, "https://example.fr/") - - // See https://github.com/gohugoio/hugo/issues/10912 - b.AssertFileContent("public/fr/index.html", "French Home Page", "String Resource: /docs/text/pipes.txt") - b.AssertFileContent("public/fr/text/pipes.txt", "Hugo Pipes") - b.AssertFileContent("public/en/index.html", "Default Home Page", "String Resource: /docs/text/pipes.txt") - b.AssertFileContent("public/en/text/pipes.txt", "Hugo Pipes") - b.AssertFileContent("public/nn/index.html", "Default Home Page", "String Resource: /docs/text/pipes.txt") - - // Check paginators - b.AssertFileContent("public/en/page/1/index.html", `refresh" content="0; url=https://example.com/docs/"`) - b.AssertFileContent("public/nn/page/1/index.html", `refresh" content="0; url=https://example.no/"`) - b.AssertFileContent("public/en/sect/page/2/index.html", "List Page 2", "Hello", "https://example.com/docs/sect/", "\"/docs/sect/page/3/") - b.AssertFileContent("public/fr/sect/page/2/index.html", "List Page 2", "Bonjour", "https://example.fr/sect/") - - // Check bundles - - bundleEn := s1.getPage(kinds.KindPage, "bundles/b1/index.en.md") - c.Assert(bundleEn, qt.Not(qt.IsNil)) - c.Assert(bundleEn.RelPermalink(), qt.Equals, "/docs/bundles/b1/") - c.Assert(len(bundleEn.Resources()), qt.Equals, 1) - - b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data") - b.AssertFileContent("public/en/bundles/b1/index.html", " image/png: /docs/bundles/b1/logo.png") - - bundleFr := s2.getPage(kinds.KindPage, "bundles/b1/index.md") - c.Assert(bundleFr, qt.Not(qt.IsNil)) - c.Assert(bundleFr.RelPermalink(), qt.Equals, "/bundles/b1/") - c.Assert(len(bundleFr.Resources()), qt.Equals, 1) - b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") - b.AssertFileContent("public/fr/bundles/b1/index.html", " image/png: /bundles/b1/logo.png") + b.AssertFileContent("public/en/enpages/mybundle-en/file1.txt", "File 1 en.") + b.AssertFileContent("public/fr/section/mybundle/file1.txt", "File 1 fr.") + b.AssertFileContent("public/en/enpages/mybundle-en/file2.txt", "File 2 en.") + b.AssertFileContent("public/fr/section/mybundle/file2.txt", "File 2 en.") } |