github.com/olliephillips/hugo@v0.42.2/hugolib/hugo_sites_multihost_test.go (about) 1 package hugolib 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestMultihosts(t *testing.T) { 10 t.Parallel() 11 12 assert := require.New(t) 13 14 var configTemplate = ` 15 paginate = 1 16 disablePathToLower = true 17 defaultContentLanguage = "fr" 18 defaultContentLanguageInSubdir = false 19 staticDir = ["s1", "s2"] 20 21 [permalinks] 22 other = "/somewhere/else/:filename" 23 24 [Taxonomies] 25 tag = "tags" 26 27 [Languages] 28 [Languages.en] 29 staticDir2 = ["ens1", "ens2"] 30 baseURL = "https://example.com/docs" 31 weight = 10 32 title = "In English" 33 languageName = "English" 34 35 [Languages.fr] 36 staticDir2 = ["frs1", "frs2"] 37 baseURL = "https://example.fr" 38 weight = 20 39 title = "Le Français" 40 languageName = "Français" 41 42 [Languages.nn] 43 staticDir2 = ["nns1", "nns2"] 44 baseURL = "https://example.no" 45 weight = 30 46 title = "På nynorsk" 47 languageName = "Nynorsk" 48 49 ` 50 51 b := newMultiSiteTestDefaultBuilder(t).WithConfigFile("toml", configTemplate) 52 b.CreateSites().Build(BuildCfg{}) 53 54 b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Hello") 55 56 s1 := b.H.Sites[0] 57 58 s1h := s1.getPage(KindHome) 59 assert.True(s1h.IsTranslated()) 60 assert.Len(s1h.Translations(), 2) 61 assert.Equal("https://example.com/docs/", s1h.Permalink()) 62 63 // For “regular multilingual” we kept the aliases pages with url in front matter 64 // as a literal value that we use as is. 65 // There is an ambiguity in the guessing. 66 // For multihost, we never want any content in the root. 67 // 68 // check url in front matter: 69 pageWithURLInFrontMatter := s1.getPage(KindPage, "sect/doc3.en.md") 70 assert.NotNil(pageWithURLInFrontMatter) 71 assert.Equal("/superbob", pageWithURLInFrontMatter.URL()) 72 assert.Equal("/docs/superbob/", pageWithURLInFrontMatter.RelPermalink()) 73 b.AssertFileContent("public/en/superbob/index.html", "doc3|Hello|en") 74 75 // check alias: 76 b.AssertFileContent("public/en/al/alias1/index.html", `content="0; url=https://example.com/docs/superbob/"`) 77 b.AssertFileContent("public/en/al/alias2/index.html", `content="0; url=https://example.com/docs/superbob/"`) 78 79 s2 := b.H.Sites[1] 80 81 s2h := s2.getPage(KindHome) 82 assert.Equal("https://example.fr/", s2h.Permalink()) 83 84 b.AssertFileContent("public/fr/index.html", "French Home Page") 85 b.AssertFileContent("public/en/index.html", "Default Home Page") 86 87 // Check paginators 88 b.AssertFileContent("public/en/page/1/index.html", `refresh" content="0; url=https://example.com/docs/"`) 89 b.AssertFileContent("public/nn/page/1/index.html", `refresh" content="0; url=https://example.no/"`) 90 b.AssertFileContent("public/en/sect/page/2/index.html", "List Page 2", "Hello", "https://example.com/docs/sect/", "\"/docs/sect/page/3/") 91 b.AssertFileContent("public/fr/sect/page/2/index.html", "List Page 2", "Bonjour", "https://example.fr/sect/") 92 93 // Check bundles 94 95 bundleEn := s1.getPage(KindPage, "bundles/b1/index.en.md") 96 require.NotNil(t, bundleEn) 97 require.Equal(t, "/docs/bundles/b1/", bundleEn.RelPermalink()) 98 require.Equal(t, 1, len(bundleEn.Resources)) 99 logoEn := bundleEn.Resources.GetByPrefix("logo") 100 require.NotNil(t, logoEn) 101 require.Equal(t, "/docs/bundles/b1/logo.png", logoEn.RelPermalink()) 102 b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data") 103 104 bundleFr := s2.getPage(KindPage, "bundles/b1/index.md") 105 require.NotNil(t, bundleFr) 106 require.Equal(t, "/bundles/b1/", bundleFr.RelPermalink()) 107 require.Equal(t, 1, len(bundleFr.Resources)) 108 logoFr := bundleFr.Resources.GetByPrefix("logo") 109 require.NotNil(t, logoFr) 110 require.Equal(t, "/bundles/b1/logo.png", logoFr.RelPermalink()) 111 b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") 112 113 }