From dc2f6ae27aefbc6b086bc83b6fc4d0021588dffd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 12 Nov 2025 09:33:56 +0100 Subject: [PATCH] sitesmatrix: Clary default dimension values And make the default content version `v.1.0.0`. It has not much practical difference, but this encourages semver usage. --- hugolib/page_test.go | 4 +- .../sitematrix_integration_test.go | 37 +++++++++++++------ hugolib/versions/versions.go | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 88308120c..3f6aa93c4 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1441,8 +1441,8 @@ Rotate(language): {{ with .Rotate "language" }}{{ range . }}{{ template "printp" b := Test(t, files) - b.AssertFileContent("public/en/foo/index.html", "Rotate(language): /en/bar/:/l:en/v:v1/r:guest|/en/foo/:/l:en/v:v1/r:guest|$") - b.AssertFileContent("public/en/bar/index.html", "Rotate(language): /en/bar/:/l:en/v:v1/r:guest|/en/foo/:/l:en/v:v1/r:guest|$") + b.AssertFileContent("public/en/foo/index.html", "Rotate(language): /en/bar/:/l:en/v:v1.0.0/r:guest|/en/foo/:/l:en/v:v1.0.0/r:guest|$") + b.AssertFileContent("public/en/bar/index.html", "Rotate(language): /en/bar/:/l:en/v:v1.0.0/r:guest|/en/foo/:/l:en/v:v1.0.0/r:guest|$") } func TestChompBOM(t *testing.T) { diff --git a/hugolib/sitesmatrix/sitematrix_integration_test.go b/hugolib/sitesmatrix/sitematrix_integration_test.go index 5ab6ebba3..048fcc791 100644 --- a/hugolib/sitesmatrix/sitematrix_integration_test.go +++ b/hugolib/sitesmatrix/sitematrix_integration_test.go @@ -482,8 +482,8 @@ title = "Scandinavian p1" {{ .Title }}|{{ .Site.Language.Name }}|{{ .Site.Version.Name }}|p1: {{ .Params.p1 }}| ` b := hugolib.Test(t, files) - b.AssertFileContent("public/en/mysection/p1/index.html", "English p1|en|v1|p1: p1cascade|") - b.AssertFileContent("public/sv/mysection/scandinavianpages/p1/index.html", "Scandinavian p1|sv|v1|p1: p1cascadescandinavian|") + b.AssertFileContent("public/en/mysection/p1/index.html", "English p1|en|v1.0.0|p1: p1cascade|") + b.AssertFileContent("public/sv/mysection/scandinavianpages/p1/index.html", "Scandinavian p1|sv|v1.0.0|p1: p1cascadescandinavian|") } func TestCascadeMatrixConfigPerLanguage(t *testing.T) { @@ -523,8 +523,8 @@ title: "Nynorsk p1" ` b := hugolib.Test(t, files) - b.AssertFileContent("public/en/mysection/p1/index.html", "English p1|en|v1|p1: p1cascadeen|p2: p2cascadeall|") - b.AssertFileContent("public/nn/mysection/p1/index.html", "Nynorsk p1|nn|v1|p1: p1cascadenn|p2: p2cascadeall|") + b.AssertFileContent("public/en/mysection/p1/index.html", "English p1|en|v1.0.0|p1: p1cascadeen|p2: p2cascadeall|") + b.AssertFileContent("public/nn/mysection/p1/index.html", "Nynorsk p1|nn|v1.0.0|p1: p1cascadenn|p2: p2cascadeall|") } func TestCascadeMatrixNoHomeContent(t *testing.T) { @@ -544,9 +544,9 @@ p2 = "p2cascadeall" ` b := hugolib.Test(t, files) - b.AssertFileContent("public/en/index.html", "|home|en|v1|p1: p1cascadeall|p2: p2cascadeall|") - b.AssertFileContent("public/en/mysection/index.html", "Mysections|section|en|v1|p1: p1cascadeall|p2: p2cascadeall|") - b.AssertFileContent("public/en/mysection/p1/index.html", "|page|en|v1|p1: p1cascadeall|p2: p2cascadeall|") + b.AssertFileContent("public/en/index.html", "|home|en|v1.0.0|p1: p1cascadeall|p2: p2cascadeall|") + b.AssertFileContent("public/en/mysection/index.html", "Mysections|section|en|v1.0.0|p1: p1cascadeall|p2: p2cascadeall|") + b.AssertFileContent("public/en/mysection/p1/index.html", "|page|en|v1.0.0|p1: p1cascadeall|p2: p2cascadeall|") } func TestMountCascadeFrontMatterSitesMatrixAndComplementsShouldBeMerged(t *testing.T) { @@ -708,11 +708,11 @@ title: "Theme p1" sEn := b.SiteHelper("en", "", "") sNN := b.SiteHelper("nn", "", "guest") - b.Assert(sEn.PageHelper("/p1").MatrixFromPageConfig()["matrix"], qt.DeepEquals, map[string][]string{"languages": {"en"}, "roles": {"guest"}, "versions": {"v1"}}) + b.Assert(sEn.PageHelper("/p1").MatrixFromPageConfig()["matrix"], qt.DeepEquals, map[string][]string{"languages": {"en"}, "roles": {"guest"}, "versions": {"v1.0.0"}}) b.Assert(sEn.PageHelper("/p2").MatrixFromPageConfig()["matrix"], qt.DeepEquals, map[string][]string{ "languages": {"en", "nn"}, "roles": {"guest"}, - "versions": {"v1"}, + "versions": {"v1.0.0"}, }) p1NN := sNN.PageHelper("/p1") @@ -721,13 +721,13 @@ title: "Theme p1" b.Assert(p2NN.MatrixFromPageConfig()["matrix"], qt.DeepEquals, map[string][]string{ "languages": {"en", "nn"}, "roles": {"guest"}, - "versions": {"v1"}, + "versions": {"v1.0.0"}, }) b.Assert(p1NN.MatrixFromFile()["matrix"], qt.DeepEquals, map[string][]string{ "languages": {"nn"}, // It's defined as ** in the mount. "roles": {"guest"}, - "versions": {"v1"}, + "versions": {"v1.0.0"}, }) } @@ -1020,6 +1020,21 @@ All.{{ .Title }}| b.AssertFileContent("public/de/p1/index.html", "All.P1 de|") } +func TestSitesMatrixDefaultValues(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ["rss", "sitemap", "section", "taxonomy", "term"] +-- layouts/all.html -- +All. {{ .Title }}|Lang: {{ .Site.Language.Name }}|Ver: {{ .Site.Version.Name }}|Role: {{ .Site.Role.Name }}| +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/index.html", "All. |Lang: en|Ver: v1.0.0|Role: guest|") +} + func newSitesMatrixContentBenchmarkBuilder(t testing.TB, numPages int, skipRender, multipleDimensions bool) *hugolib.IntegrationTestBuilder { files := ` -- hugo.toml -- diff --git a/hugolib/versions/versions.go b/hugolib/versions/versions.go index a2c743d18..acb71d63a 100644 --- a/hugolib/versions/versions.go +++ b/hugolib/versions/versions.go @@ -127,7 +127,7 @@ func (r VersionsInternal) ForEachIndex() iter.Seq[int] { } } -const defaultContentVersionFallback = "v1" +const defaultContentVersionFallback = "v1.0.0" func (r *VersionsInternal) init(defaultContentVersion string) error { if r.versionConfigs == nil { -- 2.39.5