Reimplement and simplify Hugo's template system

See #13541 for details.

Fixes #13545
Fixes #13515
Closes #7964
Closes #13365
Closes #12988
Closes #4891
This commit is contained in:
Bjørn Erik Pedersen
2025-04-06 19:55:35 +02:00
parent 812ea0b325
commit 83cfdd78ca
138 changed files with 5342 additions and 4396 deletions

View File

@@ -15,7 +15,6 @@ package hugolib
import (
"fmt"
"path/filepath"
"testing"
qt "github.com/frankban/quicktest"
@@ -102,10 +101,18 @@ URL: {{ $pag.URL }}
// Issue 6023
func TestPaginateWithSort(t *testing.T) {
b := newTestSitesBuilder(t).WithSimpleConfigFile()
b.WithTemplatesAdded("index.html", `{{ range (.Paginate (sort .Site.RegularPages ".File.Filename" "desc")).Pages }}|{{ .File.Filename }}{{ end }}`)
b.Build(BuildCfg{}).AssertFileContent("public/index.html",
filepath.FromSlash("|content/sect/doc1.nn.md|content/sect/doc1.nb.md|content/sect/doc1.fr.md|content/sect/doc1.en.md"))
files := `
-- hugo.toml --
-- content/a/a.md --
-- content/z/b.md --
-- content/x/b.md --
-- content/x/a.md --
-- layouts/home.html --
Paginate: {{ range (.Paginate (sort .Site.RegularPages ".File.Filename" "desc")).Pages }}|{{ .Path }}{{ end }}
`
b := Test(t, files)
b.AssertFileContent("public/index.html", "Paginate: |/z/b|/x/b|/x/a|/a/a")
}
// https://github.com/gohugoio/hugo/issues/6797
@@ -176,12 +183,12 @@ Paginator: {{ .Paginator }}
func TestNilPointerErrorMessage(t *testing.T) {
files := `
-- hugo.toml --
-- hugo.toml --
-- content/p1.md --
-- layouts/_default/single.html --
Home Filename: {{ site.Home.File.Filename }}
`
b, err := TestE(t, files)
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, `_default/single.html:1:22: executing "_default/single.html" File is nil; wrap it in if or with: {{ with site.Home.File }}{{ .Filename }}{{ end }}`)
b.Assert(err.Error(), qt.Contains, `single.html:1:22: executing "single.html" File is nil; wrap it in if or with: {{ with site.Home.File }}{{ .Filename }}{{ end }}`)
}