diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-07-17 11:18:29 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-07-18 00:07:20 +0200 |
commit | 3eb313fef495a39731dafa6bddbf77760090230d (patch) | |
tree | aa93e04123fa299e27b4d701b81d7976865d299c /hugolib/hugo_sites_build_test.go | |
parent | b93417aa1d3d38a9e56bad25937e0e638a113faf (diff) | |
download | hugo-3eb313fef495a39731dafa6bddbf77760090230d.tar.gz hugo-3eb313fef495a39731dafa6bddbf77760090230d.zip |
Simplify .Site.GetPage etc.
This commit is a follow up to a recent overhaul of the GetPage/ref/relref implemenation.
The most important change in this commit is the update to `.Site.GetPage`:
* To reduce the amount of breakage in the wild to its minimum, I have reworked .Site.GetPage with some rules:
* We cannot support more than 2 arguments, i.e. .Site.GetPage "page" "posts" "mypage.md" will now throw an error. I think this is the most uncommon syntax and should be OK. It is an easy fix to change the above to .Site.GetPage "/posts/mypage.md" or similar.
* .Site.GetPage "home", .Site.GetPage "home" "" and .Site.GetPage "home" "/" will give you the home page. This means that if you have page in root with the name home.md you need to do .Site.GetPage "/home.md" or similar
This commit also fixes some multilingual issues, most notable it is now possible to do cross-language ref/relref lookups by prepending the language code to the path, e.g. `/jp/posts/mypage.md`.
This commit also reverts the site building tests related to this to "Hugo 0.44 state", to get better control of the changes made.
Closes #4147
Closes #4727
Closes #4728
Closes #4728
Closes #4726
Closes #4652
Diffstat (limited to 'hugolib/hugo_sites_build_test.go')
-rw-r--r-- | hugolib/hugo_sites_build_test.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 34b67be5e..4c32fa2f6 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -186,12 +186,12 @@ p1 = "p1en" assert.Len(sites, 2) nnSite := sites[0] - nnHome, _ := nnSite.getPage(nil, "/") + nnHome := nnSite.getPage(KindHome) assert.Len(nnHome.AllTranslations(), 2) assert.Len(nnHome.Translations(), 1) assert.True(nnHome.IsTranslated()) - enHome, _ := sites[1].getPage(nil, "/") + enHome := sites[1].getPage(KindHome) p1, err := enHome.Param("p1") assert.NoError(err) @@ -242,7 +242,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Nil(t, gp2) enSite := sites[0] - enSiteHome, _ := enSite.getPage(nil, "/") + enSiteHome := enSite.getPage(KindHome) require.True(t, enSiteHome.IsTranslated()) require.Equal(t, "en", enSite.Language.Lang) @@ -310,10 +310,10 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { // isn't ideal in a multilingual setup. You want a way to get the current language version if available. // Now you can do lookups with translation base name to get that behaviour. // Let us test all the regular page variants: - getPageDoc1En, _ := enSite.getPage(nil, filepath.ToSlash(doc1en.Path())) - getPageDoc1EnBase, _ := enSite.getPage(nil, "sect/doc1") - getPageDoc1Fr, _ := frSite.getPage(nil, filepath.ToSlash(doc1fr.Path())) - getPageDoc1FrBase, _ := frSite.getPage(nil, "sect/doc1") + getPageDoc1En := enSite.getPage(KindPage, filepath.ToSlash(doc1en.Path())) + getPageDoc1EnBase := enSite.getPage(KindPage, "sect/doc1") + getPageDoc1Fr := frSite.getPage(KindPage, filepath.ToSlash(doc1fr.Path())) + getPageDoc1FrBase := frSite.getPage(KindPage, "sect/doc1") require.Equal(t, doc1en, getPageDoc1En) require.Equal(t, doc1fr, getPageDoc1Fr) require.Equal(t, doc1en, getPageDoc1EnBase) @@ -331,7 +331,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello", "LingoDefault") // Check node translations - homeEn, _ := enSite.getPage(nil, "/") + homeEn := enSite.getPage(KindHome) require.NotNil(t, homeEn) require.Len(t, homeEn.Translations(), 3) require.Equal(t, "fr", homeEn.Translations()[0].Lang()) @@ -341,7 +341,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Equal(t, "På bokmål", homeEn.Translations()[2].title, configSuffix) require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix) - sectFr, _ := frSite.getPage(nil, "sect") + sectFr := frSite.getPage(KindSection, "sect") require.NotNil(t, sectFr) require.Equal(t, "fr", sectFr.Lang()) @@ -351,12 +351,12 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { nnSite := sites[2] require.Equal(t, "nn", nnSite.Language.Lang) - taxNn, _ := nnSite.getPage(nil, "lag") + taxNn := nnSite.getPage(KindTaxonomyTerm, "lag") require.NotNil(t, taxNn) require.Len(t, taxNn.Translations(), 1) require.Equal(t, "nb", taxNn.Translations()[0].Lang()) - taxTermNn, _ := nnSite.getPage(nil, "lag/sogndal") + taxTermNn := nnSite.getPage(KindTaxonomy, "lag", "sogndal") require.NotNil(t, taxTermNn) require.Len(t, taxTermNn.Translations(), 1) require.Equal(t, "nb", taxTermNn.Translations()[0].Lang()) @@ -411,7 +411,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { } // Check bundles - bundleFr, _ := frSite.getPage(nil, "bundles/b1/index.md") + bundleFr := frSite.getPage(KindPage, "bundles/b1/index.md") require.NotNil(t, bundleFr) require.Equal(t, "/blog/fr/bundles/b1/", bundleFr.RelPermalink()) require.Equal(t, 1, len(bundleFr.Resources)) @@ -420,7 +420,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Equal(t, "/blog/fr/bundles/b1/logo.png", logoFr.RelPermalink()) b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data") - bundleEn, _ := enSite.getPage(nil, "bundles/b1/index.en.md") + bundleEn := enSite.getPage(KindPage, "bundles/b1/index.en.md") require.NotNil(t, bundleEn) require.Equal(t, "/blog/en/bundles/b1/", bundleEn.RelPermalink()) require.Equal(t, 1, len(bundleEn.Resources)) @@ -582,7 +582,7 @@ func TestMultiSitesRebuild(t *testing.T) { docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html") require.True(t, strings.Contains(docFr, "Salut"), "No Salut") - homeEn, _ := enSite.getPage(nil, "/") + homeEn := enSite.getPage(KindHome) require.NotNil(t, homeEn) assert.Len(homeEn.Translations(), 3) require.Equal(t, "fr", homeEn.Translations()[0].Lang()) @@ -678,7 +678,7 @@ title = "Svenska" require.True(t, svSite.Language.Lang == "sv", svSite.Language.Lang) require.True(t, frSite.Language.Lang == "fr", frSite.Language.Lang) - homeEn, _ := enSite.getPage(nil, "/") + homeEn := enSite.getPage(KindHome) require.NotNil(t, homeEn) require.Len(t, homeEn.Translations(), 4) require.Equal(t, "sv", homeEn.Translations()[0].Lang()) |