Skip to content

Commit

Permalink
Handle build vs _build in front matter
Browse files Browse the repository at this point in the history
* Throw a detailed error message in the mentioned case
* Also fixed a dropped error

Fixes #11970
  • Loading branch information
bep committed Feb 3, 2024
1 parent e33a632 commit a66480f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
12 changes: 9 additions & 3 deletions hugolib/content_map_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,9 @@ func (sa *sitePagesAssembler) applyAggregates() error {
}

// Combine the cascade map with front matter.
pageBundle.setMetaPost(cascade)
if err := pageBundle.setMetaPost(cascade); err != nil {
return false, err
}

// We receive cascade values from above. If this leads to a change compared
// to the previous value, we need to mark the page and its dependencies as changed.
Expand Down Expand Up @@ -1304,7 +1306,9 @@ func (sa *sitePagesAssembler) applyAggregates() error {
if data != nil {
cascade = data.(map[page.PageMatcher]maps.Params)
}
pageResource.setMetaPost(cascade)
if err := pageResource.setMetaPost(cascade); err != nil {
return false, err
}
}

return false, nil
Expand Down Expand Up @@ -1369,7 +1373,9 @@ func (sa *sitePagesAssembler) applyAggregatesToTaxonomiesAndTerms() error {
if data != nil {
cascade = data.(map[page.PageMatcher]maps.Params)
}
p.setMetaPost(cascade)
if err := p.setMetaPost(cascade); err != nil {
return false, err
}

if err := sa.pageMap.treeTaxonomyEntries.WalkPrefix(
doctree.LockTypeRead,
Expand Down
18 changes: 16 additions & 2 deletions hugolib/page__meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,29 @@ func (p *pageState) setMetaPostParams() error {
}

var buildConfig any
var isNewBuildKeyword bool
if v, ok := pm.pageConfig.Params["_build"]; ok {
buildConfig = v
} else {
buildConfig = pm.pageConfig.Params["build"]
isNewBuildKeyword = true
}

pm.pageConfig.Build, err = pagemeta.DecodeBuildConfig(buildConfig)
if err != nil {
return err
//lint:ignore ST1005 end user message.
var msgDetail string
if isNewBuildKeyword {
msgDetail = `. We renamed the _build keyword to build in Hugo 0.123.0. We recommend putting user defined params in the params section, e.g.:
---
title: "My Title"
params:
build: "My Build"
---
´
`
}
return fmt.Errorf("failed to decode build config in front matter: %s%s", err, msgDetail)
}

var sitemapSet bool
Expand Down
21 changes: 21 additions & 0 deletions hugolib/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,24 @@ lang = 'nn'
b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil)
}

// Issue 11970.
func TestFrontMatterBuildIsHugoKeyword(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
baseURL = "https://example.org/"
-- content/p1.md --
---
title: "P1"
build: "foo"
---
-- layouts/_default/single.html --
Params: {{ range $k, $v := .Params }}{{ $k }}: {{ $v }}|{{ end }}$
`
b, err := TestE(t, files)

b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, "We renamed the _build keyword")
}

0 comments on commit a66480f

Please sign in to comment.