From 467444ef649b35676ed5b4198eb8165b347d9119 Mon Sep 17 00:00:00 2001 From: hugoreleaser Date: Sat, 23 Nov 2024 15:46:37 +0000 Subject: [PATCH 001/387] releaser: Prepare repository for 0.140.0-DEV [ci skip] --- common/hugo/version_current.go | 6 +++--- hugoreleaser.env | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/hugo/version_current.go b/common/hugo/version_current.go index 8af8030bb..39a350415 100644 --- a/common/hugo/version_current.go +++ b/common/hugo/version_current.go @@ -17,7 +17,7 @@ package hugo // This should be the only one. var CurrentVersion = Version{ Major: 0, - Minor: 139, - PatchLevel: 2, - Suffix: "", + Minor: 140, + PatchLevel: 0, + Suffix: "-DEV", } diff --git a/hugoreleaser.env b/hugoreleaser.env index b9cc5806c..d76795ecf 100644 --- a/hugoreleaser.env +++ b/hugoreleaser.env @@ -1,7 +1,8 @@ # Release env. # These will be replaced by script before release. -HUGORELEASER_TAG=v0.139.1 -HUGORELEASER_COMMITISH=21299a7a677287e1ec7a6465f3bb3dd5864826ec +HUGORELEASER_TAG=v0.139.2 +HUGORELEASER_COMMITISH=770f548b47b39e6f0fd4da1cc80552024e5829e1 + From dea158c88514afbd24f67558039ec4d20cd5aed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 25 Nov 2024 10:39:17 +0100 Subject: [PATCH 002/387] commands: Fix flaw in the livereload logic I guess most commonly an issue with TailwindCSS editing in templates: * Build changes both CSS and index.html => reload OK. * Build changes both CSS and index.html and some other files => only CSS reloaded. The above would fix itself with one more edit, but that's annoying. --- commands/hugobuilder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go index 95129018f..51493938d 100644 --- a/commands/hugobuilder.go +++ b/commands/hugobuilder.go @@ -966,7 +966,7 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher, pathToRefresh := h.PathSpec.RelURL(paths.ToSlashTrimLeading(otherChanges[0]), false) lrl.Logf("refreshing %q", pathToRefresh) livereload.RefreshPath(pathToRefresh) - } else if len(cssChanges) == 0 { + } else if len(cssChanges) == 0 || len(otherChanges) > 1 { lrl.Logf("force refresh") livereload.ForceRefresh() } From 88b7868fbdaf7c84c1dd14712535a593a34e9c3a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:30:24 +0000 Subject: [PATCH 003/387] build(deps): bump github.com/tetratelabs/wazero from 1.8.1 to 1.8.2 Bumps [github.com/tetratelabs/wazero](https://github.com/tetratelabs/wazero) from 1.8.1 to 1.8.2. - [Release notes](https://github.com/tetratelabs/wazero/releases) - [Commits](https://github.com/tetratelabs/wazero/compare/v1.8.1...v1.8.2) --- updated-dependencies: - dependency-name: github.com/tetratelabs/wazero dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 03df8b3db..36fdec39d 100644 --- a/go.mod +++ b/go.mod @@ -69,7 +69,7 @@ require ( github.com/spf13/pflag v1.0.5 github.com/tdewolff/minify/v2 v2.20.37 github.com/tdewolff/parse/v2 v2.7.15 - github.com/tetratelabs/wazero v1.8.1 + github.com/tetratelabs/wazero v1.8.2 github.com/yuin/goldmark v1.7.8 github.com/yuin/goldmark-emoji v1.0.4 go.uber.org/automaxprocs v1.5.3 diff --git a/go.sum b/go.sum index 2920de0f8..d07cac1bd 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,6 @@ github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA= github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw= github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA= github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c= -github.com/bep/godartsass/v2 v2.2.0 h1:3hO9Dt4BOnxkKmRxc+OpoKVFrDvBycpSCXEdElVAMVI= -github.com/bep/godartsass/v2 v2.2.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo= github.com/bep/godartsass/v2 v2.3.0 h1:gEMyq/bNn4hxpUSwy/NKyOTqPqVh3AedhMHvQR+x0kU= github.com/bep/godartsass/v2 v2.3.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo= github.com/bep/golibsass v1.2.0 h1:nyZUkKP/0psr8nT6GR2cnmt99xS93Ji82ZD9AgOK6VI= @@ -454,8 +452,8 @@ github.com/tdewolff/parse/v2 v2.7.15/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W github.com/tdewolff/test v1.0.11-0.20231101010635-f1265d231d52/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739 h1:IkjBCtQOOjIn03u/dMQK9g+Iw9ewps4mCl1nB8Sscbo= github.com/tdewolff/test v1.0.11-0.20240106005702-7de5f7df4739/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8= -github.com/tetratelabs/wazero v1.8.1 h1:NrcgVbWfkWvVc4UtT4LRLDf91PsOzDzefMdwhLfA550= -github.com/tetratelabs/wazero v1.8.1/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs= +github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4= +github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= From 7e130e34f202d400891cd2acaaf196c049b17f7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 08:22:59 +0000 Subject: [PATCH 004/387] build(deps): bump github.com/bep/godartsass/v2 from 2.3.0 to 2.3.1 Bumps [github.com/bep/godartsass/v2](https://github.com/bep/godartsass) from 2.3.0 to 2.3.1. - [Release notes](https://github.com/bep/godartsass/releases) - [Commits](https://github.com/bep/godartsass/compare/v2.3.0...v2.3.1) --- updated-dependencies: - dependency-name: github.com/bep/godartsass/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 36fdec39d..a82ecb5f8 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/bep/debounce v1.2.0 github.com/bep/gitmap v1.6.0 github.com/bep/goat v0.5.0 - github.com/bep/godartsass/v2 v2.3.0 + github.com/bep/godartsass/v2 v2.3.1 github.com/bep/golibsass v1.2.0 github.com/bep/gowebp v0.3.0 github.com/bep/helpers v0.5.0 diff --git a/go.sum b/go.sum index d07cac1bd..e60627e68 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA= github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw= github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA= github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c= -github.com/bep/godartsass/v2 v2.3.0 h1:gEMyq/bNn4hxpUSwy/NKyOTqPqVh3AedhMHvQR+x0kU= -github.com/bep/godartsass/v2 v2.3.0/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo= +github.com/bep/godartsass/v2 v2.3.1 h1:Lh9v0IxAaB+toyZrZ+XYNYcGXI1PzGzvZ4u8tRWTnLw= +github.com/bep/godartsass/v2 v2.3.1/go.mod h1:AcP8QgC+OwOXEq6im0WgDRYK7scDsmZCEW62o1prQLo= github.com/bep/golibsass v1.2.0 h1:nyZUkKP/0psr8nT6GR2cnmt99xS93Ji82ZD9AgOK6VI= github.com/bep/golibsass v1.2.0/go.mod h1:DL87K8Un/+pWUS75ggYv41bliGiolxzDKWJAq3eJ1MA= github.com/bep/gowebp v0.3.0 h1:MhmMrcf88pUY7/PsEhMgEP0T6fDUnRTMpN8OclDrbrY= From fc3d1cbadb48d5f8e10fcd811377de6b8453ea8d Mon Sep 17 00:00:00 2001 From: huajin tong <137764712+thirdkeyword@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:20:02 +0800 Subject: [PATCH 005/387] Fix some typos --- common/hugo/hugo.go | 2 +- hugolib/doctree/nodeshifttree.go | 2 +- markup/blackfriday/anchors.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index 11ec40e0b..e480baa94 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -426,7 +426,7 @@ func DeprecateLevel(item, alternative, version string, level logg.Level) { loggers.Log().Logger().WithLevel(level).WithField(loggers.FieldNameCmd, "deprecated").Logf(msg) } -// We ususally do about one minor version a month. +// We usually do about one minor version a month. // We want people to run at least the current and previous version without any warnings. // We want people who don't update Hugo that often to see the warnings and errors before we remove the feature. func deprecationLogLevelFromVersion(ver string) logg.Level { diff --git a/hugolib/doctree/nodeshifttree.go b/hugolib/doctree/nodeshifttree.go index 36382c2d7..497e9f02e 100644 --- a/hugolib/doctree/nodeshifttree.go +++ b/hugolib/doctree/nodeshifttree.go @@ -59,7 +59,7 @@ type ( ) // NodeShiftTree is the root of a tree that can be shaped using the Shape method. -// Note that multipled shapes of the same tree is meant to be used concurrently, +// Note that multiplied shapes of the same tree is meant to be used concurrently, // so use the applicable locking when needed. type NodeShiftTree[T any] struct { tree *radix.Tree diff --git a/markup/blackfriday/anchors.go b/markup/blackfriday/anchors.go index 7b0b41854..e00c24c9a 100644 --- a/markup/blackfriday/anchors.go +++ b/markup/blackfriday/anchors.go @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package blackfriday holds some compability functions for the old Blackfriday v1 Markdown engine. +// Package blackfriday holds some compatibility functions for the old Blackfriday v1 Markdown engine. package blackfriday import "unicode" From c1dc35dd712fc926cc7eaa2bf607fb4716794dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 29 Nov 2024 12:13:49 +0100 Subject: [PATCH 006/387] Fix server edits of resources included in shortcode/hooks Fixes #13093 --- hugolib/page__content.go | 4 +++ hugolib/rebuild_test.go | 77 ++++++++++++++++++++++++++++++++++------ identity/finder.go | 25 ++++++++----- tpl/template.go | 1 - 4 files changed, 86 insertions(+), 21 deletions(-) diff --git a/hugolib/page__content.go b/hugolib/page__content.go index 4ec91f7b5..b5527a281 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -863,6 +863,10 @@ type cachedContentScope struct { } func (c *cachedContentScope) prepareContext(ctx context.Context) context.Context { + // A regular page's shortcode etc. may be rendered by e.g. the home page, + // so we need to track any changes to this content's page. + ctx = tpl.Context.DependencyManagerScopedProvider.Set(ctx, c.pco.po.p) + // The markup scope is recursive, so if already set to a non zero value, preserve that value. if s := hugo.GetMarkupScope(ctx); s != "" || s == c.scope { return ctx diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index 2219fe812..ff1f8267e 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -21,8 +21,13 @@ const rebuildFilesSimple = ` baseURL = "https://example.com" disableKinds = ["term", "taxonomy", "sitemap", "robotstxt", "404"] disableLiveReload = true +[outputFormats] + [outputFormats.rss] + weight = 10 + [outputFormats.html] + weight = 20 [outputs] -home = ["html"] +home = ["rss", "html"] section = ["html"] page = ["html"] -- content/mysection/_index.md -- @@ -58,6 +63,21 @@ Home Text Content. title: "myothersectionpage" --- myothersectionpage Content. +-- content/mythirdsection/mythirdsectionpage.md -- +--- +title: "mythirdsectionpage" +--- +mythirdsectionpage Content. +{{< myshortcodetext >}} +§§§ myothertext +foo +§§§ +-- assets/mytext.txt -- +Assets My Text. +-- assets/myshortcodetext.txt -- +Assets My Shortcode Text. +-- assets/myothertext.txt -- +Assets My Other Text. -- layouts/_default/single.html -- Single: {{ .Title }}|{{ .Content }}$ Resources: {{ range $i, $e := .Resources }}{{ $i }}:{{ .RelPermalink }}|{{ .Content }}|{{ end }}$ @@ -68,6 +88,13 @@ Len Resources: {{ len .Resources }}| Resources: {{ range $i, $e := .Resources }}{{ $i }}:{{ .RelPermalink }}|{{ .Content }}|{{ end }}$ -- layouts/shortcodes/foo.html -- Foo. +-- layouts/shortcodes/myshortcodetext.html -- +{{ warnf "mytext %s" now}} +{{ $r := resources.Get "myshortcodetext.txt" }} +My Shortcode Text: {{ $r.Content }}|{{ $r.Permalink }}| +-- layouts/_default/_markup/render-codeblock-myothertext.html -- +{{ $r := resources.Get "myothertext.txt" }} +My Other Text: {{ $r.Content }}|{{ $r.Permalink }}| ` @@ -83,6 +110,34 @@ func TestRebuildEditTextFileInLeafBundle(t *testing.T) { b.AssertRenderCountContent(1) } +func TestRebuildEditTextFileInShortcode(t *testing.T) { + t.Parallel() + for i := 0; i < 3; i++ { + b := TestRunning(t, rebuildFilesSimple) + b.AssertFileContent("public/mythirdsection/mythirdsectionpage/index.html", + "Text: Assets My Shortcode Text.") + b.EditFileReplaceAll("assets/myshortcodetext.txt", "My Shortcode Text", "My Shortcode Text Edited").Build() + fmt.Println(b.LogString()) + b.AssertFileContent("public/mythirdsection/mythirdsectionpage/index.html", + "Text: Assets My Shortcode Text Edited.") + + } +} + +func TestRebuildEditTextFileInHook(t *testing.T) { + t.Parallel() + for i := 0; i < 3; i++ { + b := TestRunning(t, rebuildFilesSimple) + b.AssertFileContent("public/mythirdsection/mythirdsectionpage/index.html", + "Text: Assets My Other Text.") + b.AssertFileContent("public/myothertext.txt", "Assets My Other Text.") + b.EditFileReplaceAll("assets/myothertext.txt", "My Other Text", "My Other Text Edited").Build() + b.AssertFileContent("public/mythirdsection/mythirdsectionpage/index.html", + "Text: Assets My Other Text Edited.") + + } +} + func TestRebuiEditUnmarshaledYamlFileInLeafBundle(t *testing.T) { files := ` -- hugo.toml -- @@ -140,8 +195,8 @@ func TestRebuildRenameTextFileInLeafBundle(t *testing.T) { b.RenameFile("content/mysection/mysectionbundle/mysectionbundletext.txt", "content/mysection/mysectionbundle/mysectionbundletext2.txt").Build() b.AssertFileContent("public/mysection/mysectionbundle/index.html", "mysectionbundletext2", "My Section Bundle Text 2 Content.", "Len Resources: 2|") - b.AssertRenderCountPage(5) - b.AssertRenderCountContent(6) + b.AssertRenderCountPage(8) + b.AssertRenderCountContent(8) }) } @@ -161,8 +216,8 @@ func TestRebuilEditContentFileThenAnother(t *testing.T) { b.EditFileReplaceAll("content/myothersection/myothersectionpage.md", "myothersectionpage Content.", "myothersectionpage Content Edited.").Build() b.AssertFileContent("public/myothersection/myothersectionpage/index.html", "myothersectionpage Content Edited") - b.AssertRenderCountPage(1) - b.AssertRenderCountContent(1) + b.AssertRenderCountPage(2) + b.AssertRenderCountContent(2) } func TestRebuildRenameTextFileInBranchBundle(t *testing.T) { @@ -171,7 +226,7 @@ func TestRebuildRenameTextFileInBranchBundle(t *testing.T) { b.RenameFile("content/mysection/mysectiontext.txt", "content/mysection/mysectiontext2.txt").Build() b.AssertFileContent("public/mysection/index.html", "mysectiontext2", "My Section") - b.AssertRenderCountPage(2) + b.AssertRenderCountPage(3) b.AssertRenderCountContent(2) } @@ -181,14 +236,14 @@ func TestRebuildRenameTextFileInHomeBundle(t *testing.T) { b.RenameFile("content/hometext.txt", "content/hometext2.txt").Build() b.AssertFileContent("public/index.html", "hometext2", "Home Text Content.") - b.AssertRenderCountPage(3) + b.AssertRenderCountPage(5) } func TestRebuildRenameDirectoryWithLeafBundle(t *testing.T) { b := TestRunning(t, rebuildFilesSimple) b.RenameDir("content/mysection/mysectionbundle", "content/mysection/mysectionbundlerenamed").Build() b.AssertFileContent("public/mysection/mysectionbundlerenamed/index.html", "My Section Bundle") - b.AssertRenderCountPage(1) + b.AssertRenderCountPage(2) } func TestRebuildRenameDirectoryWithBranchBundle(t *testing.T) { @@ -197,7 +252,7 @@ func TestRebuildRenameDirectoryWithBranchBundle(t *testing.T) { b.AssertFileContent("public/mysectionrenamed/index.html", "My Section") b.AssertFileContent("public/mysectionrenamed/mysectionbundle/index.html", "My Section Bundle") b.AssertFileContent("public/mysectionrenamed/mysectionbundle/mysectionbundletext.txt", "My Section Bundle Text 2 Content.") - b.AssertRenderCountPage(3) + b.AssertRenderCountPage(5) } func TestRebuildRenameDirectoryWithRegularPageUsedInHome(t *testing.T) { @@ -296,7 +351,7 @@ func TestRebuildRenameDirectoryWithBranchBundleFastRender(t *testing.T) { b.AssertFileContent("public/mysectionrenamed/index.html", "My Section") b.AssertFileContent("public/mysectionrenamed/mysectionbundle/index.html", "My Section Bundle") b.AssertFileContent("public/mysectionrenamed/mysectionbundle/mysectionbundletext.txt", "My Section Bundle Text 2 Content.") - b.AssertRenderCountPage(3) + b.AssertRenderCountPage(5) } func TestRebuilErrorRecovery(t *testing.T) { @@ -1239,7 +1294,7 @@ Single. return strings.Replace(s, "red", "blue", 1) }).Build() - b.AssertRenderCountPage(3) + b.AssertRenderCountPage(4) b.AssertFileContent("public/index.html", "Home.", "") } diff --git a/identity/finder.go b/identity/finder.go index 91fac7237..b1a08d061 100644 --- a/identity/finder.go +++ b/identity/finder.go @@ -122,17 +122,21 @@ func (f *Finder) Contains(id, in Identity, maxDepth int) FinderResult { defer putSearchID(sid) - if r := f.checkOne(sid, in, 0); r > 0 { + r := FinderNotFound + if i := f.checkOne(sid, in, 0); i > r { + r = i + } + if r == FinderFound { return r } m := GetDependencyManager(in) if m != nil { - if r := f.checkManager(sid, m, 0); r > 0 { - return r + if i := f.checkManager(sid, m, 0); i > r { + r = i } } - return FinderNotFound + return r } func (f *Finder) checkMaxDepth(sid *searchID, level int) FinderResult { @@ -279,15 +283,18 @@ func (f *Finder) search(sid *searchID, m Manager, depth int) FinderResult { var r FinderResult m.forEeachIdentity( func(v Identity) bool { - if r > 0 { - panic("should be terminated") + i := f.checkOne(sid, v, depth) + if i > r { + r = i } - r = f.checkOne(sid, v, depth) - if r > 0 { + if r == FinderFound { return true } m := GetDependencyManager(v) - if r = f.checkManager(sid, m, depth+1); r > 0 { + if i := f.checkManager(sid, m, depth+1); i > r { + r = i + } + if r == FinderFound { return true } return false diff --git a/tpl/template.go b/tpl/template.go index 18a31e231..39c6b4f1c 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -172,7 +172,6 @@ type contextKey string var Context = struct { DependencyManagerScopedProvider hcontext.ContextDispatcher[identity.DependencyManagerScopedProvider] GetDependencyManagerInCurrentScope func(context.Context) identity.Manager - SetDependencyManagerInCurrentScope func(context.Context, identity.Manager) context.Context DependencyScope hcontext.ContextDispatcher[int] Page hcontext.ContextDispatcher[page] IsInGoldmark hcontext.ContextDispatcher[bool] From 2f6864387cd31b975914e8373d4bf38bddbd47bc Mon Sep 17 00:00:00 2001 From: hugoreleaser Date: Fri, 29 Nov 2024 15:36:56 +0000 Subject: [PATCH 007/387] releaser: Bump versions for release of 0.139.3 [ci skip] --- common/hugo/version_current.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/hugo/version_current.go b/common/hugo/version_current.go index 39a350415..b69c55775 100644 --- a/common/hugo/version_current.go +++ b/common/hugo/version_current.go @@ -17,7 +17,7 @@ package hugo // This should be the only one. var CurrentVersion = Version{ Major: 0, - Minor: 140, - PatchLevel: 0, - Suffix: "-DEV", + Minor: 139, + PatchLevel: 3, + Suffix: "", } From 487bb96474363070a9b5b22ce4640f80329e91e4 Mon Sep 17 00:00:00 2001 From: hugoreleaser Date: Fri, 29 Nov 2024 15:51:07 +0000 Subject: [PATCH 008/387] releaser: Prepare repository for 0.140.0-DEV [ci skip] --- common/hugo/version_current.go | 6 +++--- hugoreleaser.env | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/hugo/version_current.go b/common/hugo/version_current.go index b69c55775..39a350415 100644 --- a/common/hugo/version_current.go +++ b/common/hugo/version_current.go @@ -17,7 +17,7 @@ package hugo // This should be the only one. var CurrentVersion = Version{ Major: 0, - Minor: 139, - PatchLevel: 3, - Suffix: "", + Minor: 140, + PatchLevel: 0, + Suffix: "-DEV", } diff --git a/hugoreleaser.env b/hugoreleaser.env index d76795ecf..4c8ed54a6 100644 --- a/hugoreleaser.env +++ b/hugoreleaser.env @@ -1,7 +1,8 @@ # Release env. # These will be replaced by script before release. -HUGORELEASER_TAG=v0.139.2 -HUGORELEASER_COMMITISH=770f548b47b39e6f0fd4da1cc80552024e5829e1 +HUGORELEASER_TAG=v0.139.3 +HUGORELEASER_COMMITISH=2f6864387cd31b975914e8373d4bf38bddbd47bc + From b529859008fae916a0509645da539072e62dfcb1 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Wed, 4 Dec 2024 09:21:21 -0800 Subject: [PATCH 009/387] markup/tableofcontents: Cast Fragments.ToHTML args to int Closes #13107 --- hugolib/page__content.go | 13 ++-- markup/goldmark/convert_test.go | 4 +- markup/tableofcontents/tableofcontents.go | 23 ++++-- .../tableofcontents_integration_test.go | 78 +++++++++++++++++++ .../tableofcontents/tableofcontents_test.go | 24 ++++-- 5 files changed, 120 insertions(+), 22 deletions(-) diff --git a/hugolib/page__content.go b/hugolib/page__content.go index b5527a281..f7579f182 100644 --- a/hugolib/page__content.go +++ b/hugolib/page__content.go @@ -730,16 +730,15 @@ func (c *cachedContentScope) contentToC(ctx context.Context) (contentTableOfCont isHTML := cp.po.p.m.pageConfig.ContentMediaType.IsHTML() if !isHTML { - createAndSetToC := func(tocProvider converter.TableOfContentsProvider) { + createAndSetToC := func(tocProvider converter.TableOfContentsProvider) error { cfg := p.s.ContentSpec.Converters.GetMarkupConfig() ct.tableOfContents = tocProvider.TableOfContents() - ct.tableOfContentsHTML = template.HTML( - ct.tableOfContents.ToHTML( - cfg.TableOfContents.StartLevel, - cfg.TableOfContents.EndLevel, - cfg.TableOfContents.Ordered, - ), + ct.tableOfContentsHTML, err = ct.tableOfContents.ToHTML( + cfg.TableOfContents.StartLevel, + cfg.TableOfContents.EndLevel, + cfg.TableOfContents.Ordered, ) + return err } // If the converter supports doing the parsing separately, we do that. diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index 6048bce39..a35441aff 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -208,8 +208,8 @@ unsafe = true toc, ok := b.(converter.TableOfContentsProvider) c.Assert(ok, qt.Equals, true) - tocString := string(toc.TableOfContents().ToHTML(1, 2, false)) - c.Assert(tocString, qt.Contains, "TableOfContents") + tocHTML, _ := toc.TableOfContents().ToHTML(1, 2, false) + c.Assert(string(tocHTML), qt.Contains, "TableOfContents") } func TestConvertAutoIDAsciiOnly(t *testing.T) { diff --git a/markup/tableofcontents/tableofcontents.go b/markup/tableofcontents/tableofcontents.go index 49a9cdeb7..560e421b7 100644 --- a/markup/tableofcontents/tableofcontents.go +++ b/markup/tableofcontents/tableofcontents.go @@ -14,11 +14,13 @@ package tableofcontents import ( + "fmt" "html/template" "sort" "strings" "github.com/gohugoio/hugo/common/collections" + "github.com/spf13/cast" ) // Empty is an empty ToC. @@ -133,19 +135,30 @@ func (toc *Fragments) addAt(h *Heading, row, level int) { } // ToHTML renders the ToC as HTML. -func (toc *Fragments) ToHTML(startLevel, stopLevel int, ordered bool) template.HTML { +func (toc *Fragments) ToHTML(startLevel, stopLevel any, ordered bool) (template.HTML, error) { if toc == nil { - return "" + return "", nil } + + iStartLevel, err := cast.ToIntE(startLevel) + if err != nil { + return "", fmt.Errorf("startLevel: %w", err) + } + + iStopLevel, err := cast.ToIntE(stopLevel) + if err != nil { + return "", fmt.Errorf("stopLevel: %w", err) + } + b := &tocBuilder{ s: strings.Builder{}, h: toc.Headings, - startLevel: startLevel, - stopLevel: stopLevel, + startLevel: iStartLevel, + stopLevel: iStopLevel, ordered: ordered, } b.Build() - return template.HTML(b.s.String()) + return template.HTML(b.s.String()), nil } func (toc Fragments) walk(fn func(*Heading)) { diff --git a/markup/tableofcontents/tableofcontents_integration_test.go b/markup/tableofcontents/tableofcontents_integration_test.go index 87a7c0108..e6ae03ce2 100644 --- a/markup/tableofcontents/tableofcontents_integration_test.go +++ b/markup/tableofcontents/tableofcontents_integration_test.go @@ -14,6 +14,7 @@ package tableofcontents_test import ( + "strings" "testing" "github.com/gohugoio/hugo/hugolib" @@ -43,3 +44,80 @@ disableKinds = ['page','rss','section','sitemap','taxonomy','term'] "heading-l5|5|Heading L5", ) } + +// Issue #13107 +func TestToHTMLArgTypes(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','section','rss','sitemap','taxonomy','term'] +-- layouts/_default/single.html -- +{{ .Fragments.ToHTML .Params.toc.startLevel .Params.toc.endLevel false }} +-- content/json.md -- +{ + "title": "json", + "params": { + "toc": { + "startLevel": 2, + "endLevel": 4 + } + } +} +CONTENT +-- content/toml.md -- ++++ +title = 'toml' +[params.toc] +startLevel = 2 +endLevel = 4 ++++ +CONTENT +-- content/yaml.md -- +--- +title: yaml +params: + toc: + startLevel: 2 + endLevel: 4 +--- +CONTENT +` + + content := ` +# Level One +## Level Two +### Level Three +#### Level Four +##### Level Five +###### Level Six + ` + + want := ` + +` + + files = strings.ReplaceAll(files, "CONTENT", content) + + b := hugolib.Test(t, files) + b.AssertFileContentEquals("public/json/index.html", strings.TrimSpace(want)) + b.AssertFileContentEquals("public/toml/index.html", strings.TrimSpace(want)) + b.AssertFileContentEquals("public/yaml/index.html", strings.TrimSpace(want)) + + files = strings.ReplaceAll(files, `2`, `"x"`) + + b, _ = hugolib.TestE(t, files) + b.AssertLogMatches(`error calling ToHTML: startLevel: unable to cast "x" of type string`) +} diff --git a/markup/tableofcontents/tableofcontents_test.go b/markup/tableofcontents/tableofcontents_test.go index 3af9c4eb6..9ec7ec293 100644 --- a/markup/tableofcontents/tableofcontents_test.go +++ b/markup/tableofcontents/tableofcontents_test.go @@ -45,7 +45,8 @@ func TestToc(t *testing.T) { toc.addAt(&Heading{Title: "1-H3-1", ID: "1-h2-2"}, 0, 2) toc.addAt(&Heading{Title: "Heading 2", ID: "h1-2"}, 1, 0) - got := string(toc.ToHTML(1, -1, false)) + tocHTML, _ := toc.ToHTML(1, -1, false) + got := string(tocHTML) c.Assert(got, qt.Equals, ``, qt.Commentf(got)) - got = string(toc.ToHTML(1, 1, false)) + tocHTML, _ = toc.ToHTML(1, 1, false) + got = string(tocHTML) c.Assert(got, qt.Equals, ``, qt.Commentf(got)) - got = string(toc.ToHTML(1, 2, false)) + tocHTML, _ = toc.ToHTML(1, 2, false) + got = string(tocHTML) c.Assert(got, qt.Equals, ``, qt.Commentf(got)) - got = string(toc.ToHTML(2, 2, false)) + tocHTML, _ = toc.ToHTML(2, 2, false) + got = string(tocHTML) c.Assert(got, qt.Equals, ``, qt.Commentf(got)) - got = string(toc.ToHTML(1, -1, true)) + tocHTML, _ = toc.ToHTML(1, -1, true) + got = string(tocHTML) c.Assert(got, qt.Equals, `