diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-07 20:24:37 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-22 09:57:03 +0100 |
commit | ec2d502b4f214b9505dcd57713d2236c606985e8 (patch) | |
tree | b0d2943606d7169ff315687b6c226cd017701757 /hugolib/node_as_page_test.go | |
parent | 698b994f714174449fd1ea37c39058ea14f6deee (diff) |
node to page: Handle translations
Updates #2297
Diffstat (limited to 'hugolib/node_as_page_test.go')
-rw-r--r-- | hugolib/node_as_page_test.go | 197 |
1 files changed, 161 insertions, 36 deletions
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go index 0cd2b3a5e..3a97d318a 100644 --- a/hugolib/node_as_page_test.go +++ b/hugolib/node_as_page_test.go @@ -50,42 +50,7 @@ func TestNodesAsPage(t *testing.T) { testCommonResetState() writeLayoutsForNodeAsPageTests(t) - - writeSource(t, filepath.Join("content", "_index.md"), `--- -title: Home Sweet Home! ---- -Home **Content!** -`) - - writeSource(t, filepath.Join("content", "sect1", "_index.md"), `--- -title: Section1 ---- -Section1 **Content!** -`) - - writeSource(t, filepath.Join("content", "sect2", "_index.md"), `--- -title: Section2 ---- -Section2 **Content!** -`) - - writeSource(t, filepath.Join("content", "categories", "hugo", "_index.md"), `--- -title: Taxonomy Hugo ---- -Taxonomy Hugo **Content!** -`) - - writeSource(t, filepath.Join("content", "categories", "web", "_index.md"), `--- -title: Taxonomy Web ---- -Taxonomy Web **Content!** -`) - - writeSource(t, filepath.Join("content", "categories", "_index.md"), `--- -title: Taxonomy Term Categories ---- -Taxonomy Term Categories **Content!** -`) + writeNodePagesForNodeAsPageTests("", t) // Add some regular pages for i := 1; i <= 4; i++ { @@ -253,6 +218,166 @@ Content Page %02d } +func TestNodesAsPageMultilingual(t *testing.T) { + + nodePageFeatureFlag = true + defer toggleNodePageFeatureFlag() + + testCommonResetState() + + writeLayoutsForNodeAsPageTests(t) + + writeSource(t, "config.toml", + ` +paginage = 1 +title = "Hugo Multilingual Rocks!" +rssURI = "customrss.xml" + +[languages] +[languages.nn] +languageName = "Nynorsk" +weight = 1 +title = "Hugo på norsk" +defaultContentLanguage = "nn" + +[languages.en] +languageName = "English" +weight = 2 +title = "Hugo in English" +`) + + for _, lang := range []string{"nn", "en"} { + for i := 1; i <= 4; i++ { + sect := "sect1" + if i > 2 { + sect = "sect2" + } + writeSource(t, filepath.Join("content", sect, fmt.Sprintf("regular%d.%s.md", i, lang)), fmt.Sprintf(`--- +title: Page %02d +categories: [ + "Hugo", + "Web" +] +--- +Content Page %02d +`, i, i)) + } + } + + // Only write node pages for the English side of the fence + writeNodePagesForNodeAsPageTests("en", t) + + if err := LoadGlobalConfig("", "config.toml"); err != nil { + t.Fatalf("Failed to load config: %s", err) + } + + sites, err := NewHugoSitesFromConfiguration() + + if err != nil { + t.Fatalf("Failed to create sites: %s", err) + } + + if len(sites.Sites) != 2 { + t.Fatalf("Got %d sites", len(sites.Sites)) + } + + err = sites.Build(BuildCfg{}) + + if err != nil { + t.Fatalf("Failed to build sites: %s", err) + } + + // The en language has content pages + + // TODO(bep) np alias URL check + + assertFileContent(t, filepath.Join("public", "nn", "index.html"), true, + "Index Title: Hugo på norsk") + assertFileContent(t, filepath.Join("public", "en", "index.html"), true, + "Index Title: Home Sweet Home!", "<strong>Content!</strong>") + + // Taxonomy list + assertFileContent(t, filepath.Join("public", "nn", "categories", "hugo", "index.html"), true, + "Taxonomy Title: Hugo") + assertFileContent(t, filepath.Join("public", "en", "categories", "hugo", "index.html"), true, + "Taxonomy Title: Taxonomy Hugo") + + // Taxonomy terms + assertFileContent(t, filepath.Join("public", "nn", "categories", "index.html"), true, + "Taxonomy Terms Title: Categories") + assertFileContent(t, filepath.Join("public", "en", "categories", "index.html"), true, + "Taxonomy Terms Title: Taxonomy Term Categories") + + // Sections + assertFileContent(t, filepath.Join("public", "nn", "sect1", "index.html"), true, + "Section Title: Sect1s") + assertFileContent(t, filepath.Join("public", "nn", "sect2", "index.html"), true, + "Section Title: Sect2s") + assertFileContent(t, filepath.Join("public", "en", "sect1", "index.html"), true, + "Section Title: Section1") + assertFileContent(t, filepath.Join("public", "en", "sect2", "index.html"), true, + "Section Title: Section2") + + // RSS + assertFileContent(t, filepath.Join("public", "nn", "customrss.xml"), true, "Recent content in Hugo på norsk on Hugo på norsk", "<rss") + assertFileContent(t, filepath.Join("public", "nn", "sect1", "customrss.xml"), true, "Recent content in Sect1s on Hugo på norsk", "<rss") + assertFileContent(t, filepath.Join("public", "nn", "sect2", "customrss.xml"), true, "Recent content in Sect2s on Hugo på norsk", "<rss") + assertFileContent(t, filepath.Join("public", "nn", "categories", "hugo", "customrss.xml"), true, "Recent content in Hugo on Hugo på norsk", "<rss") + assertFileContent(t, filepath.Join("public", "nn", "categories", "web", "customrss.xml"), true, "Recent content in Web on Hugo på norsk", "<rss") + + assertFileContent(t, filepath.Join("public", "en", "customrss.xml"), true, "Recent content in Home Sweet Home! on Hugo in English", "<rss") + assertFileContent(t, filepath.Join("public", "en", "sect1", "customrss.xml"), true, "Recent content in Section1 on Hugo in English", "<rss") + assertFileContent(t, filepath.Join("public", "en", "sect2", "customrss.xml"), true, "Recent content in Section2 on Hugo in English", "<rss") + assertFileContent(t, filepath.Join("public", "en", "categories", "hugo", "customrss.xml"), true, "Recent content in Taxonomy Hugo on Hugo in English", "<rss") + assertFileContent(t, filepath.Join("public", "en", "categories", "web", "customrss.xml"), true, "Recent content in Taxonomy Web on Hugo in English", "<rss") + +} + +func writeNodePagesForNodeAsPageTests(lang string, t *testing.T) { + + filename := "_index.md" + + if lang != "" { + filename = fmt.Sprintf("_index.%s.md", lang) + } + + writeSource(t, filepath.Join("content", filename), `--- +title: Home Sweet Home! +--- +Home **Content!** +`) + + writeSource(t, filepath.Join("content", "sect1", filename), `--- +title: Section1 +--- +Section1 **Content!** +`) + + writeSource(t, filepath.Join("content", "sect2", filename), `--- +title: Section2 +--- +Section2 **Content!** +`) + + writeSource(t, filepath.Join("content", "categories", "hugo", filename), `--- +title: Taxonomy Hugo +--- +Taxonomy Hugo **Content!** +`) + + writeSource(t, filepath.Join("content", "categories", "web", filename), `--- +title: Taxonomy Web +--- +Taxonomy Web **Content!** +`) + + writeSource(t, filepath.Join("content", "categories", filename), `--- +title: Taxonomy Term Categories +--- +Taxonomy Term Categories **Content!** +`) +} + func writeLayoutsForNodeAsPageTests(t *testing.T) { writeSource(t, filepath.Join("layouts", "index.html"), ` Index Title: {{ .Title }} |