From da58a911781c1627648a77219771252753fca34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 2 Nov 2017 08:25:20 +0100 Subject: [PATCH] Add multilingual multihost support Updates #4027 --- hugolib/hugo_sites_build_test.go | 2 +- hugolib/hugo_sites_multihost_test.go | 62 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 hugolib/hugo_sites_multihost_test.go diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 96e2c66b2ed..079f0fcfaec 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -1269,7 +1269,7 @@ lag: t.Fatalf("Failed to create sites: %s", err) } - if len(sites.Sites) != 4 { + if len(sites.Sites) == 0 { t.Fatalf("Got %d sites", len(sites.Sites)) } diff --git a/hugolib/hugo_sites_multihost_test.go b/hugolib/hugo_sites_multihost_test.go new file mode 100644 index 00000000000..f6a75c2fe1d --- /dev/null +++ b/hugolib/hugo_sites_multihost_test.go @@ -0,0 +1,62 @@ +package hugolib + +import ( + "testing" + + "github.com/spf13/afero" + "github.com/stretchr/testify/require" +) + +func TestMultihosts(t *testing.T) { + t.Parallel() + + var multiSiteTOMLConfigTemplate = ` +paginate = 1 +disablePathToLower = true +defaultContentLanguage = "{{ .DefaultContentLanguage }}" + +[permalinks] +other = "/somewhere/else/:filename" + +[Taxonomies] +tag = "tags" + +[Languages] +[Languages.en] +baseURL = "https://example.com" +weight = 10 +title = "In English" +languageName = "English" + +[Languages.fr] +baseURL = "https://example.fr" +weight = 20 +title = "Le Français" +languageName = "Français" + +[Languages.nn] +baseURL = "https://example.no" +weight = 30 +title = "På nynorsk" +languageName = "Nynorsk" + +` + + siteConfig := testSiteConfig{Fs: afero.NewMemMapFs(), DefaultContentLanguage: "fr", DefaultContentLanguageInSubdir: true} + sites := createMultiTestSites(t, siteConfig, multiSiteTOMLConfigTemplate) + fs := sites.Fs + cfg := BuildCfg{Watching: true} + th := testHelper{sites.Cfg, fs, t} + assert := require.New(t) + + err := sites.Build(cfg) + assert.NoError(err) + + th.assertFileContent("public/en/sect/doc1-slug/index.html", "Hello") + enSite := sites.Sites[0] + enSiteHome := enSite.getPage(KindHome) + assert.True(enSiteHome.IsTranslated()) + assert.Len(enSiteHome.Translations(), 2) + assert.Equal("https://example.com/", enSiteHome.Permalink()) + +}