mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-28 17:22:38 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c46d603a02 | |||
| 69ede10edc | |||
| bb59a7ed97 | |||
| 503d20954f | |||
| 68e95327f7 | |||
| 9cd7db61d3 | |||
| c892e75fbc | |||
| 4255d13d3e | |||
| c8b9f9f81c | |||
| 7be7f89bf6 | |||
| c8e400b621 | |||
| 9dd687027f | |||
| 1961327536 | |||
| cc3574ef4f | |||
| fe84cc218e | |||
| babcb339a8 | |||
| 7203a95a60 | |||
| fb084390cd | |||
| fb51b698b3 | |||
| 6b867972ec |
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2022 The Hugo Authors.
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Vendored
+31
-7
@@ -67,7 +67,7 @@ func New(opts Options) *Cache {
|
||||
evictedIdentities := collections.NewStack[identity.Identity]()
|
||||
|
||||
onEvict := func(k, v any) {
|
||||
if !opts.Running {
|
||||
if !opts.Watching {
|
||||
return
|
||||
}
|
||||
identity.WalkIdentitiesShallow(v, func(level int, id identity.Identity) bool {
|
||||
@@ -97,7 +97,7 @@ type Options struct {
|
||||
CheckInterval time.Duration
|
||||
MaxSize int
|
||||
MinMaxSize int
|
||||
Running bool
|
||||
Watching bool
|
||||
}
|
||||
|
||||
// Options for a partition.
|
||||
@@ -385,13 +385,37 @@ type Partition[K comparable, V any] struct {
|
||||
|
||||
// GetOrCreate gets or creates a value for the given key.
|
||||
func (p *Partition[K, V]) GetOrCreate(key K, create func(key K) (V, error)) (V, error) {
|
||||
v, err := p.doGetOrCreate(key, create)
|
||||
if err != nil {
|
||||
return p.zero, err
|
||||
}
|
||||
if resource.StaleVersion(v) > 0 {
|
||||
p.c.Delete(key)
|
||||
return p.doGetOrCreate(key, create)
|
||||
}
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (p *Partition[K, V]) doGetOrCreate(key K, create func(key K) (V, error)) (V, error) {
|
||||
v, _, err := p.c.GetOrCreate(key, create)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (p *Partition[K, V]) GetOrCreateWitTimeout(key K, duration time.Duration, create func(key K) (V, error)) (V, error) {
|
||||
v, err := p.doGetOrCreateWitTimeout(key, duration, create)
|
||||
if err != nil {
|
||||
return p.zero, err
|
||||
}
|
||||
if resource.StaleVersion(v) > 0 {
|
||||
p.c.Delete(key)
|
||||
return p.doGetOrCreateWitTimeout(key, duration, create)
|
||||
}
|
||||
return v, err
|
||||
}
|
||||
|
||||
// GetOrCreateWitTimeout gets or creates a value for the given key and times out if the create function
|
||||
// takes too long.
|
||||
func (p *Partition[K, V]) GetOrCreateWitTimeout(key K, duration time.Duration, create func(key K) (V, error)) (V, error) {
|
||||
func (p *Partition[K, V]) doGetOrCreateWitTimeout(key K, duration time.Duration, create func(key K) (V, error)) (V, error) {
|
||||
resultch := make(chan V, 1)
|
||||
errch := make(chan error, 1)
|
||||
|
||||
@@ -448,7 +472,7 @@ func (p *Partition[K, V]) clearOnRebuild(changeset ...identity.Identity) {
|
||||
|
||||
shouldDelete := func(key K, v V) bool {
|
||||
// We always clear elements marked as stale.
|
||||
if resource.IsStaleAny(v) {
|
||||
if resource.StaleVersion(v) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -503,8 +527,8 @@ func (p *Partition[K, V]) Keys() []K {
|
||||
|
||||
func (p *Partition[K, V]) clearStale() {
|
||||
p.c.DeleteFunc(func(key K, v V) bool {
|
||||
isStale := resource.IsStaleAny(v)
|
||||
if isStale {
|
||||
staleVersion := resource.StaleVersion(v)
|
||||
if staleVersion > 0 {
|
||||
p.trace.Log(
|
||||
logg.StringFunc(
|
||||
func() string {
|
||||
@@ -514,7 +538,7 @@ func (p *Partition[K, V]) clearStale() {
|
||||
)
|
||||
}
|
||||
|
||||
return isStale
|
||||
return staleVersion > 0
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Vendored
+6
-6
@@ -29,12 +29,12 @@ var (
|
||||
)
|
||||
|
||||
type testItem struct {
|
||||
name string
|
||||
isStale bool
|
||||
name string
|
||||
staleVersion uint32
|
||||
}
|
||||
|
||||
func (t testItem) IsStale() bool {
|
||||
return t.isStale
|
||||
func (t testItem) StaleVersion() uint32 {
|
||||
return t.staleVersion
|
||||
}
|
||||
|
||||
func (t testItem) IdentifierBase() string {
|
||||
@@ -109,7 +109,7 @@ func newTestCache(t *testing.T) *Cache {
|
||||
|
||||
p2.GetOrCreate("clearBecauseStale", func(string) (testItem, error) {
|
||||
return testItem{
|
||||
isStale: true,
|
||||
staleVersion: 32,
|
||||
}, nil
|
||||
})
|
||||
|
||||
@@ -121,7 +121,7 @@ func newTestCache(t *testing.T) *Cache {
|
||||
|
||||
p2.GetOrCreate("clearNever", func(string) (testItem, error) {
|
||||
return testItem{
|
||||
isStale: false,
|
||||
staleVersion: 0,
|
||||
}, nil
|
||||
})
|
||||
|
||||
|
||||
@@ -327,12 +327,12 @@ func (r *rootCommand) Name() string {
|
||||
}
|
||||
|
||||
func (r *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args []string) error {
|
||||
if !r.buildWatch {
|
||||
defer r.timeTrack(time.Now(), "Total")
|
||||
}
|
||||
|
||||
b := newHugoBuilder(r, nil)
|
||||
|
||||
if !r.buildWatch {
|
||||
defer b.postBuild("Total", time.Now())
|
||||
}
|
||||
|
||||
if err := b.loadConfig(cd, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+14
-2
@@ -75,9 +75,14 @@ type hugoBuilder struct {
|
||||
errState hugoBuilderErrState
|
||||
}
|
||||
|
||||
var errConfigNotSet = errors.New("config not set")
|
||||
|
||||
func (c *hugoBuilder) withConfE(fn func(conf *commonConfig) error) error {
|
||||
c.confmu.Lock()
|
||||
defer c.confmu.Unlock()
|
||||
if c.conf == nil {
|
||||
return errConfigNotSet
|
||||
}
|
||||
return fn(c.conf)
|
||||
}
|
||||
|
||||
@@ -585,7 +590,7 @@ func (c *hugoBuilder) fullRebuild(changeType string) {
|
||||
time.Sleep(2 * time.Second)
|
||||
}()
|
||||
|
||||
defer c.r.timeTrack(time.Now(), "Rebuilt")
|
||||
defer c.postBuild("Rebuilt", time.Now())
|
||||
|
||||
err := c.reloadConfig()
|
||||
if err != nil {
|
||||
@@ -855,7 +860,7 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
|
||||
c.changeDetector.PrepareNew()
|
||||
|
||||
func() {
|
||||
defer c.r.timeTrack(time.Now(), "Total")
|
||||
defer c.postBuild("Total", time.Now())
|
||||
if err := c.rebuildSites(dynamicEvents); err != nil {
|
||||
c.handleBuildErr(err, "Rebuild failed")
|
||||
}
|
||||
@@ -901,6 +906,13 @@ func (c *hugoBuilder) handleEvents(watcher *watcher.Batcher,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *hugoBuilder) postBuild(what string, start time.Time) {
|
||||
if h, err := c.hugo(); err == nil && h.Conf.Running() {
|
||||
h.LogServerAddresses()
|
||||
}
|
||||
c.r.timeTrack(start, what)
|
||||
}
|
||||
|
||||
func (c *hugoBuilder) hugo() (*hugolib.HugoSites, error) {
|
||||
var h *hugolib.HugoSites
|
||||
if err := c.withConfE(func(conf *commonConfig) error {
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ func (c *newCommand) newSiteNextStepsText(path string, format string) string {
|
||||
1. Change the current directory to ` + path + `.
|
||||
2. Create or install a theme:
|
||||
- Create a new theme with the command "hugo new theme <THEMENAME>"
|
||||
- Install a theme from https://themes.gohugo.io/
|
||||
- Or, install a theme from https://themes.gohugo.io/
|
||||
3. Edit hugo.` + format + `, setting the "theme" property to the theme name.
|
||||
4. Create new content with the command "hugo new content `)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package hugo
|
||||
// This should be the only one.
|
||||
var CurrentVersion = Version{
|
||||
Major: 0,
|
||||
Minor: 125,
|
||||
PatchLevel: 2,
|
||||
Suffix: "",
|
||||
Minor: 126,
|
||||
PatchLevel: 0,
|
||||
Suffix: "-DEV",
|
||||
}
|
||||
|
||||
@@ -71,6 +71,9 @@ func (c ConfigLanguage) Environment() string {
|
||||
}
|
||||
|
||||
func (c ConfigLanguage) IsMultihost() bool {
|
||||
if len(c.m.Languages)-len(c.config.C.DisabledLanguages) <= 1 {
|
||||
return false
|
||||
}
|
||||
return c.m.IsMultihost
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -155,7 +155,7 @@ func (d *Deps) Init() error {
|
||||
}
|
||||
|
||||
if d.MemCache == nil {
|
||||
d.MemCache = dynacache.New(dynacache.Options{Running: d.Conf.Running(), Log: d.Log})
|
||||
d.MemCache = dynacache.New(dynacache.Options{Watching: d.Conf.Watching(), Log: d.Log})
|
||||
}
|
||||
|
||||
if d.PathSpec == nil {
|
||||
|
||||
@@ -55,7 +55,7 @@ require (
|
||||
github.com/niklasfasching/go-org v1.7.0
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
|
||||
github.com/pelletier/go-toml/v2 v2.2.1
|
||||
github.com/pelletier/go-toml/v2 v2.2.2
|
||||
github.com/rogpeppe/go-internal v1.12.0
|
||||
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd
|
||||
github.com/sanity-io/litter v1.5.5
|
||||
@@ -64,8 +64,8 @@ require (
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/fsync v0.10.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/tdewolff/minify/v2 v2.20.19
|
||||
github.com/tdewolff/parse/v2 v2.7.12
|
||||
github.com/tdewolff/minify/v2 v2.20.20
|
||||
github.com/tdewolff/parse/v2 v2.7.13
|
||||
github.com/yuin/goldmark v1.7.1
|
||||
github.com/yuin/goldmark-emoji v1.0.2
|
||||
go.uber.org/automaxprocs v1.5.3
|
||||
|
||||
@@ -376,8 +376,8 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
|
||||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
|
||||
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
|
||||
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
|
||||
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
|
||||
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
|
||||
@@ -429,10 +429,10 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tdewolff/minify/v2 v2.20.19 h1:tX0SR0LUrIqGoLjXnkIzRSIbKJ7PaNnSENLD4CyH6Xo=
|
||||
github.com/tdewolff/minify/v2 v2.20.19/go.mod h1:ulkFoeAVWMLEyjuDz1ZIWOA31g5aWOawCFRp9R/MudM=
|
||||
github.com/tdewolff/parse/v2 v2.7.12 h1:tgavkHc2ZDEQVKy1oWxwIyh5bP4F5fEh/JmBwPP/3LQ=
|
||||
github.com/tdewolff/parse/v2 v2.7.12/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA=
|
||||
github.com/tdewolff/minify/v2 v2.20.20 h1:vhULb+VsW2twkplgsawAoUY957efb+EdiZ7zu5fUhhk=
|
||||
github.com/tdewolff/minify/v2 v2.20.20/go.mod h1:GYaLXFpIIwsX99apQHXfGdISUdlA98wmaoWxjT9C37k=
|
||||
github.com/tdewolff/parse/v2 v2.7.13 h1:iSiwOUkCYLNfapHoqdLcqZVgvQ0jrsao8YYKP/UJYTI=
|
||||
github.com/tdewolff/parse/v2 v2.7.13/go.mod h1:3FbJWZp3XT9OWVN3Hmfp0p/a08v4h8J9W1aghka0soA=
|
||||
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/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||
|
||||
+50
-1
@@ -329,7 +329,7 @@ cascade:
|
||||
|
||||
counters := &buildCounters{}
|
||||
b.Build(BuildCfg{testCounters: counters})
|
||||
b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 2)
|
||||
b.Assert(int(counters.contentRenderCounter.Load()), qt.Equals, 1)
|
||||
|
||||
b.AssertFileContent("public/post/index.html", `Banner: post.jpg|Layout: postlayout|Type: posttype|Content: <p>content edit</p>`)
|
||||
b.AssertFileContent("public/post/dir/p1/index.html", `Banner: post.jpg|Layout: postlayout|`)
|
||||
@@ -672,6 +672,55 @@ S1|p1:|p2:p2|
|
||||
})
|
||||
}
|
||||
|
||||
func TestCascadeEditIssue12449(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.com"
|
||||
disableKinds = ['sitemap','rss', 'home', 'taxonomy','term']
|
||||
disableLiveReload = true
|
||||
-- layouts/_default/list.html --
|
||||
Title: {{ .Title }}|{{ .Content }}|cascadeparam: {{ .Params.cascadeparam }}|
|
||||
-- layouts/_default/single.html --
|
||||
Title: {{ .Title }}|{{ .Content }}|cascadeparam: {{ .Params.cascadeparam }}|
|
||||
-- content/mysect/_index.md --
|
||||
---
|
||||
title: mysect
|
||||
cascade:
|
||||
description: descriptionvalue
|
||||
params:
|
||||
cascadeparam: cascadeparamvalue
|
||||
---
|
||||
mysect-content|
|
||||
-- content/mysect/p1/index.md --
|
||||
---
|
||||
slug: p1
|
||||
---
|
||||
p1-content|
|
||||
-- content/mysect/subsect/_index.md --
|
||||
---
|
||||
slug: subsect
|
||||
---
|
||||
subsect-content|
|
||||
`
|
||||
|
||||
b := TestRunning(t, files)
|
||||
|
||||
// Make the cascade set the title.
|
||||
b.EditFileReplaceAll("content/mysect/_index.md", "description: descriptionvalue", "title: cascadetitle").Build()
|
||||
b.AssertFileContent("public/mysect/subsect/index.html", "Title: cascadetitle|")
|
||||
|
||||
// Edit cascade title.
|
||||
b.EditFileReplaceAll("content/mysect/_index.md", "title: cascadetitle", "title: cascadetitle-edit").Build()
|
||||
b.AssertFileContent("public/mysect/subsect/index.html", "Title: cascadetitle-edit|")
|
||||
|
||||
// Revert title change.
|
||||
// The step below failed in #12449.
|
||||
b.EditFileReplaceAll("content/mysect/_index.md", "title: cascadetitle-edit", "description: descriptionvalue").Build()
|
||||
b.AssertFileContent("public/mysect/subsect/index.html", "Title: |")
|
||||
}
|
||||
|
||||
// Issue 11977.
|
||||
func TestCascadeExtensionInPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -825,6 +825,9 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
|
||||
panic(fmt.Sprintf("unknown type %T", new))
|
||||
}
|
||||
if vv.s.languagei == newp.s.languagei {
|
||||
if newp != old {
|
||||
resource.MarkStale(old)
|
||||
}
|
||||
return new
|
||||
}
|
||||
is := make(contentNodeIs, s.numLanguages)
|
||||
@@ -836,7 +839,10 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("unknown type %T", new))
|
||||
}
|
||||
resource.MarkStale(vv[newp.s.languagei])
|
||||
oldp := vv[newp.s.languagei]
|
||||
if oldp != newp {
|
||||
resource.MarkStale(oldp)
|
||||
}
|
||||
vv[newp.s.languagei] = new
|
||||
return vv
|
||||
case *resourceSource:
|
||||
@@ -845,6 +851,9 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
|
||||
panic(fmt.Sprintf("unknown type %T", new))
|
||||
}
|
||||
if vv.LangIndex() == newp.LangIndex() {
|
||||
if vv != newp {
|
||||
resource.MarkStale(vv)
|
||||
}
|
||||
return new
|
||||
}
|
||||
rs := make(resourceSources, s.numLanguages)
|
||||
@@ -856,7 +865,10 @@ func (s *contentNodeShifter) Insert(old, new contentNodeI) contentNodeI {
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("unknown type %T", new))
|
||||
}
|
||||
resource.MarkStale(vv[newp.LangIndex()])
|
||||
oldp := vv[newp.LangIndex()]
|
||||
if oldp != newp {
|
||||
resource.MarkStale(oldp)
|
||||
}
|
||||
vv[newp.LangIndex()] = newp
|
||||
return vv
|
||||
default:
|
||||
@@ -1054,7 +1066,7 @@ func (h *HugoSites) resolveAndClearStateForIdentities(
|
||||
)
|
||||
|
||||
for _, id := range changes {
|
||||
if staler, ok := id.(resource.Staler); ok && !staler.IsStale() {
|
||||
if staler, ok := id.(resource.Staler); ok {
|
||||
var msgDetail string
|
||||
if p, ok := id.(*pageState); ok && p.File() != nil {
|
||||
msgDetail = fmt.Sprintf(" (%s)", p.File().Filename())
|
||||
|
||||
@@ -23,11 +23,9 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bep/logg"
|
||||
"github.com/gohugoio/hugo/cache/dynacache"
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
@@ -47,7 +45,6 @@ import (
|
||||
"github.com/gohugoio/hugo/resources/page"
|
||||
"github.com/gohugoio/hugo/resources/page/siteidentities"
|
||||
"github.com/gohugoio/hugo/resources/postpub"
|
||||
"github.com/gohugoio/hugo/resources/resource"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
@@ -277,7 +274,7 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
|
||||
|
||||
changes := assembleChanges.Changes()
|
||||
|
||||
// Changes from the assemble step (e.g. lastMod, cascase) needs a re-calculation
|
||||
// Changes from the assemble step (e.g. lastMod, cascade) needs a re-calculation
|
||||
// of what needs to be re-built.
|
||||
if len(changes) > 0 {
|
||||
if err := h.resolveAndClearStateForIdentities(ctx, l, nil, changes); err != nil {
|
||||
@@ -598,6 +595,10 @@ type pathChange struct {
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (p pathChange) isStructuralChange() bool {
|
||||
return p.delete || p.isDir
|
||||
}
|
||||
|
||||
// processPartial prepares the Sites' sources for a partial rebuild.
|
||||
func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, config *BuildCfg, init func(config *BuildCfg) error, events []fsnotify.Event) error {
|
||||
h.Log.Trace(logg.StringFunc(func() string {
|
||||
@@ -760,48 +761,8 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
|
||||
}
|
||||
}
|
||||
case files.ComponentFolderAssets:
|
||||
p := pathInfo.Path()
|
||||
logger.Println("Asset changed", p)
|
||||
|
||||
var matches []any
|
||||
var mu sync.Mutex
|
||||
|
||||
h.MemCache.ClearMatching(
|
||||
func(k string, pm dynacache.PartitionManager) bool {
|
||||
// Avoid going through everything.
|
||||
return strings.HasPrefix(k, "/res")
|
||||
},
|
||||
func(k, v any) bool {
|
||||
if strings.Contains(k.(string), p) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
switch vv := v.(type) {
|
||||
case resource.Resources:
|
||||
// GetMatch/Match.
|
||||
for _, r := range vv {
|
||||
matches = append(matches, r)
|
||||
}
|
||||
return true
|
||||
default:
|
||||
matches = append(matches, vv)
|
||||
return true
|
||||
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
var hasID bool
|
||||
for _, r := range matches {
|
||||
identity.WalkIdentitiesShallow(r, func(level int, rid identity.Identity) bool {
|
||||
hasID = true
|
||||
changes = append(changes, rid)
|
||||
return false
|
||||
})
|
||||
}
|
||||
if !hasID {
|
||||
changes = append(changes, pathInfo)
|
||||
}
|
||||
logger.Println("Asset changed", pathInfo.Path())
|
||||
changes = append(changes, pathInfo)
|
||||
case files.ComponentFolderData:
|
||||
logger.Println("Data changed", pathInfo.Path())
|
||||
|
||||
@@ -951,12 +912,10 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
|
||||
}
|
||||
}
|
||||
|
||||
h.logServerAddresses()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *HugoSites) logServerAddresses() {
|
||||
func (h *HugoSites) LogServerAddresses() {
|
||||
if h.hugoInfo.IsMultihost() {
|
||||
for _, s := range h.Sites {
|
||||
h.Log.Printf("Web Server is available at %s (bind address %s) %s\n", s.conf.C.BaseURL, s.conf.C.ServerInterface, s.Language().Lang)
|
||||
|
||||
@@ -252,3 +252,31 @@ Files: {{ range $files }}{{ .Permalink }}|{{ end }}$
|
||||
b.AssertFileContent("public/en/enpages/mybundle-en/file2.txt", "File 2 en.")
|
||||
b.AssertFileContent("public/fr/section/mybundle/file2.txt", "File 2 en.")
|
||||
}
|
||||
|
||||
func TestMultihostAllButOneLanguageDisabledIssue12288(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
defaultContentLanguage = "en"
|
||||
disableLanguages = ["fr"]
|
||||
#baseURL = "https://example.com"
|
||||
[languages]
|
||||
[languages.en]
|
||||
baseURL = "https://example.en"
|
||||
weight = 1
|
||||
[languages.fr]
|
||||
baseURL = "https://example.fr"
|
||||
weight = 2
|
||||
-- assets/css/main.css --
|
||||
body { color: red; }
|
||||
-- layouts/index.html --
|
||||
{{ $css := resources.Get "css/main.css" | minify }}
|
||||
CSS: {{ $css.Permalink }}|{{ $css.RelPermalink }}|
|
||||
`
|
||||
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/css/main.min.css", "body{color:red}")
|
||||
b.AssertFileContent("public/index.html", "CSS: https://example.en/css/main.min.css|/css/main.min.css|")
|
||||
}
|
||||
|
||||
@@ -38,12 +38,20 @@ import (
|
||||
|
||||
type TestOpt func(*IntegrationTestConfig)
|
||||
|
||||
// TestOptRunning will enable running in integration tests.
|
||||
func TestOptRunning() TestOpt {
|
||||
return func(c *IntegrationTestConfig) {
|
||||
c.Running = true
|
||||
}
|
||||
}
|
||||
|
||||
// TestOptWatching will enable watching in integration tests.
|
||||
func TestOptWatching() TestOpt {
|
||||
return func(c *IntegrationTestConfig) {
|
||||
c.Watching = true
|
||||
}
|
||||
}
|
||||
|
||||
// Enable tracing in integration tests.
|
||||
// THis should only be used during development and not committed to the repo.
|
||||
func TestOptTrace() TestOpt {
|
||||
@@ -570,6 +578,10 @@ func (s *IntegrationTestBuilder) initBuilder() error {
|
||||
"running": s.Cfg.Running,
|
||||
"watch": s.Cfg.Running,
|
||||
})
|
||||
} else if s.Cfg.Watching {
|
||||
flags.Set("internal", maps.Params{
|
||||
"watch": s.Cfg.Watching,
|
||||
})
|
||||
}
|
||||
|
||||
if s.Cfg.WorkingDir != "" {
|
||||
@@ -817,6 +829,11 @@ type IntegrationTestConfig struct {
|
||||
// Whether to simulate server mode.
|
||||
Running bool
|
||||
|
||||
// Watch for changes.
|
||||
// This is (currently) always set to true when Running is set.
|
||||
// Note that the CLI for the server does allow for --watch=false, but that is not used in these test.
|
||||
Watching bool
|
||||
|
||||
// Will print the log buffer after the build
|
||||
Verbose bool
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ type pageCommon struct {
|
||||
page.InSectionPositioner
|
||||
page.OutputFormatsProvider
|
||||
page.PageMetaProvider
|
||||
page.PageMetaInternalProvider
|
||||
page.Positioner
|
||||
page.RawContentProvider
|
||||
page.RelatedKeywordsProvider
|
||||
|
||||
+18
-11
@@ -418,6 +418,8 @@ func (c *cachedContent) mustSource() []byte {
|
||||
|
||||
func (c *contentParseInfo) contentSource(s resource.StaleInfo) ([]byte, error) {
|
||||
key := c.sourceKey
|
||||
versionv := s.StaleVersion()
|
||||
|
||||
v, err := c.h.cacheContentSource.GetOrCreate(key, func(string) (*resources.StaleValue[[]byte], error) {
|
||||
b, err := c.readSourceAll()
|
||||
if err != nil {
|
||||
@@ -426,8 +428,8 @@ func (c *contentParseInfo) contentSource(s resource.StaleInfo) ([]byte, error) {
|
||||
|
||||
return &resources.StaleValue[[]byte]{
|
||||
Value: b,
|
||||
IsStaleFunc: func() bool {
|
||||
return s.IsStale()
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return s.StaleVersion() - versionv
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
@@ -487,7 +489,7 @@ type contentPlainPlainWords struct {
|
||||
func (c *cachedContent) contentRendered(ctx context.Context, cp *pageContentOutput) (contentSummary, error) {
|
||||
ctx = tpl.Context.DependencyScope.Set(ctx, pageDependencyScopeGlobal)
|
||||
key := c.pi.sourceKey + "/" + cp.po.f.Name
|
||||
versionv := cp.contentRenderedVersion
|
||||
versionv := c.version(cp)
|
||||
|
||||
v, err := c.pm.cacheContentRendered.GetOrCreate(key, func(string) (*resources.StaleValue[contentSummary], error) {
|
||||
cp.po.p.s.Log.Trace(logg.StringFunc(func() string {
|
||||
@@ -504,8 +506,8 @@ func (c *cachedContent) contentRendered(ctx context.Context, cp *pageContentOutp
|
||||
}
|
||||
|
||||
rs := &resources.StaleValue[contentSummary]{
|
||||
IsStaleFunc: func() bool {
|
||||
return c.IsStale() || cp.contentRenderedVersion != versionv
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return c.version(cp) - versionv
|
||||
},
|
||||
}
|
||||
|
||||
@@ -607,7 +609,7 @@ var setGetContentCallbackInContext = hcontext.NewContextDispatcher[func(*pageCon
|
||||
|
||||
func (c *cachedContent) contentToC(ctx context.Context, cp *pageContentOutput) (contentTableOfContents, error) {
|
||||
key := c.pi.sourceKey + "/" + cp.po.f.Name
|
||||
versionv := cp.contentRenderedVersion
|
||||
versionv := c.version(cp)
|
||||
|
||||
v, err := c.pm.contentTableOfContents.GetOrCreate(key, func(string) (*resources.StaleValue[contentTableOfContents], error) {
|
||||
source, err := c.pi.contentSource(c)
|
||||
@@ -713,8 +715,8 @@ func (c *cachedContent) contentToC(ctx context.Context, cp *pageContentOutput) (
|
||||
|
||||
return &resources.StaleValue[contentTableOfContents]{
|
||||
Value: ct,
|
||||
IsStaleFunc: func() bool {
|
||||
return c.IsStale() || cp.contentRenderedVersion != versionv
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return c.version(cp) - versionv
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
@@ -725,16 +727,21 @@ func (c *cachedContent) contentToC(ctx context.Context, cp *pageContentOutput) (
|
||||
return v.Value, nil
|
||||
}
|
||||
|
||||
func (c *cachedContent) version(cp *pageContentOutput) uint32 {
|
||||
// Both of these gets incremented on change.
|
||||
return c.StaleVersion() + cp.contentRenderedVersion
|
||||
}
|
||||
|
||||
func (c *cachedContent) contentPlain(ctx context.Context, cp *pageContentOutput) (contentPlainPlainWords, error) {
|
||||
key := c.pi.sourceKey + "/" + cp.po.f.Name
|
||||
|
||||
versionv := cp.contentRenderedVersion
|
||||
versionv := c.version(cp)
|
||||
|
||||
v, err := c.pm.cacheContentPlain.GetOrCreateWitTimeout(key, cp.po.p.s.Conf.Timeout(), func(string) (*resources.StaleValue[contentPlainPlainWords], error) {
|
||||
var result contentPlainPlainWords
|
||||
rs := &resources.StaleValue[contentPlainPlainWords]{
|
||||
IsStaleFunc: func() bool {
|
||||
return c.IsStale() || cp.contentRenderedVersion != versionv
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return c.version(cp) - versionv
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,9 @@ type pageMeta struct {
|
||||
// Prepare for a rebuild of the data passed in from front matter.
|
||||
func (m *pageMeta) setMetaPostPrepareRebuild() {
|
||||
params := xmaps.Clone[map[string]any](m.paramsOriginal)
|
||||
m.pageMetaParams.pageConfig.Params = params
|
||||
m.pageMetaParams.pageConfig = &pagemeta.PageConfig{
|
||||
Params: params,
|
||||
}
|
||||
m.pageMetaFrontMatter = pageMetaFrontMatter{}
|
||||
}
|
||||
|
||||
@@ -275,6 +277,7 @@ func (p *pageMeta) Weight() int {
|
||||
|
||||
func (p *pageMeta) setMetaPre(pi *contentParseInfo, logger loggers.Logger, conf config.AllProvider) error {
|
||||
frontmatter := pi.frontMatter
|
||||
|
||||
if frontmatter != nil {
|
||||
pcfg := p.pageConfig
|
||||
if pcfg == nil {
|
||||
@@ -362,6 +365,7 @@ func (ps *pageState) setMetaPost(cascade map[page.PageMatcher]maps.Params) error
|
||||
if ps.m.setMetaPostCount > 1 {
|
||||
ps.m.setMetaPostCascadeChanged = cascadeHashPre != identity.HashUint64(ps.m.pageConfig.Cascade)
|
||||
if !ps.m.setMetaPostCascadeChanged {
|
||||
|
||||
// No changes, restore any value that may be changed by aggregation.
|
||||
ps.m.pageConfig.Dates = ps.m.datesOriginal
|
||||
return nil
|
||||
|
||||
@@ -184,6 +184,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
|
||||
ResourceNameTitleProvider: m,
|
||||
ResourceParamsProvider: m,
|
||||
PageMetaProvider: m,
|
||||
PageMetaInternalProvider: m,
|
||||
RelatedKeywordsProvider: m,
|
||||
OutputFormatsProvider: page.NopPage,
|
||||
ResourceTypeProvider: pageTypesProvider,
|
||||
|
||||
@@ -89,8 +89,8 @@ type pageContentOutput struct {
|
||||
// typically included with .RenderShortcodes.
|
||||
otherOutputs map[uint64]*pageContentOutput
|
||||
|
||||
contentRenderedVersion int // Incremented on reset.
|
||||
contentRendered bool // Set on content render.
|
||||
contentRenderedVersion uint32 // Incremented on reset.
|
||||
contentRendered bool // Set on content render.
|
||||
|
||||
// Renders Markdown hooks.
|
||||
renderHooks *renderHooks
|
||||
|
||||
@@ -147,7 +147,7 @@ func (c *pagesCollector) Collect() (collectErr error) {
|
||||
false,
|
||||
func(fim hugofs.FileMetaInfo) bool {
|
||||
if fim.IsDir() {
|
||||
return true
|
||||
return id.isStructuralChange()
|
||||
}
|
||||
fimp := fim.Meta().PathInfo
|
||||
if fimp == nil {
|
||||
@@ -160,7 +160,7 @@ func (c *pagesCollector) Collect() (collectErr error) {
|
||||
} else {
|
||||
// We always start from a directory.
|
||||
collectErr = c.collectDir(id.p, id.isDir, func(fim hugofs.FileMetaInfo) bool {
|
||||
if id.delete || id.isDir {
|
||||
if id.isStructuralChange() {
|
||||
if id.isDir && fim.Meta().PathInfo.IsLeafBundle() {
|
||||
return strings.HasPrefix(fim.Meta().PathInfo.Path(), paths.AddTrailingSlash(id.p.Path()))
|
||||
}
|
||||
|
||||
+82
-18
@@ -53,6 +53,11 @@ title: "Home"
|
||||
Home Content.
|
||||
-- content/hometext.txt --
|
||||
Home Text Content.
|
||||
-- content/myothersection/myothersectionpage.md --
|
||||
---
|
||||
title: "myothersectionpage"
|
||||
---
|
||||
myothersectionpage Content.
|
||||
-- layouts/_default/single.html --
|
||||
Single: {{ .Title }}|{{ .Content }}$
|
||||
Resources: {{ range $i, $e := .Resources }}{{ $i }}:{{ .RelPermalink }}|{{ .Content }}|{{ end }}$
|
||||
@@ -121,14 +126,23 @@ func TestRebuildEditTextFileInBranchBundle(t *testing.T) {
|
||||
b.AssertRenderCountContent(1)
|
||||
}
|
||||
|
||||
func TestRebuildRenameTextFileInLeafBundle(t *testing.T) {
|
||||
b := TestRunning(t, rebuildFilesSimple)
|
||||
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
|
||||
func testRebuildBothWatchingAndRunning(t *testing.T, files string, withB func(b *IntegrationTestBuilder)) {
|
||||
t.Helper()
|
||||
for _, opt := range []TestOpt{TestOptWatching(), TestOptRunning()} {
|
||||
b := Test(t, files, opt)
|
||||
withB(b)
|
||||
}
|
||||
}
|
||||
|
||||
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(3)
|
||||
b.AssertRenderCountContent(3)
|
||||
func TestRebuildRenameTextFileInLeafBundle(t *testing.T) {
|
||||
testRebuildBothWatchingAndRunning(t, rebuildFilesSimple, func(b *IntegrationTestBuilder) {
|
||||
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRebuilEditContentFileInLeafBundle(t *testing.T) {
|
||||
@@ -138,6 +152,19 @@ func TestRebuilEditContentFileInLeafBundle(t *testing.T) {
|
||||
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Content Content Edited.")
|
||||
}
|
||||
|
||||
func TestRebuilEditContentFileThenAnother(t *testing.T) {
|
||||
b := TestRunning(t, rebuildFilesSimple)
|
||||
b.EditFileReplaceAll("content/mysection/mysectionbundle/mysectionbundlecontent.md", "Content Content.", "Content Content Edited.").Build()
|
||||
b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Content Content Edited.")
|
||||
b.AssertRenderCountPage(1)
|
||||
b.AssertRenderCountContent(2)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func TestRebuildRenameTextFileInBranchBundle(t *testing.T) {
|
||||
b := TestRunning(t, rebuildFilesSimple)
|
||||
b.AssertFileContent("public/mysection/index.html", "My Section")
|
||||
@@ -154,7 +181,7 @@ 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(2)
|
||||
b.AssertRenderCountPage(3)
|
||||
}
|
||||
|
||||
func TestRebuildRenameDirectoryWithLeafBundle(t *testing.T) {
|
||||
@@ -170,7 +197,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(2)
|
||||
b.AssertRenderCountPage(3)
|
||||
}
|
||||
|
||||
func TestRebuildRenameDirectoryWithRegularPageUsedInHome(t *testing.T) {
|
||||
@@ -269,7 +296,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(2)
|
||||
b.AssertRenderCountPage(3)
|
||||
}
|
||||
|
||||
func TestRebuilErrorRecovery(t *testing.T) {
|
||||
@@ -367,8 +394,6 @@ My short.
|
||||
}
|
||||
|
||||
func TestRebuildBaseof(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
title = "Hugo Site"
|
||||
@@ -383,12 +408,13 @@ Baseof: {{ .Title }}|
|
||||
Home: {{ .Title }}|{{ .Content }}|
|
||||
{{ end }}
|
||||
`
|
||||
b := Test(t, files, TestOptRunning())
|
||||
b.AssertFileContent("public/index.html", "Baseof: Hugo Site|", "Home: Hugo Site||")
|
||||
b.EditFileReplaceFunc("layouts/_default/baseof.html", func(s string) string {
|
||||
return strings.Replace(s, "Baseof", "Baseof Edited", 1)
|
||||
}).Build()
|
||||
b.AssertFileContent("public/index.html", "Baseof Edited: Hugo Site|", "Home: Hugo Site||")
|
||||
testRebuildBothWatchingAndRunning(t, files, func(b *IntegrationTestBuilder) {
|
||||
b.AssertFileContent("public/index.html", "Baseof: Hugo Site|", "Home: Hugo Site||")
|
||||
b.EditFileReplaceFunc("layouts/_default/baseof.html", func(s string) string {
|
||||
return strings.Replace(s, "Baseof", "Baseof Edited", 1)
|
||||
}).Build()
|
||||
b.AssertFileContent("public/index.html", "Baseof Edited: Hugo Site|", "Home: Hugo Site||")
|
||||
})
|
||||
}
|
||||
|
||||
func TestRebuildSingleWithBaseof(t *testing.T) {
|
||||
@@ -1577,3 +1603,41 @@ title: p1
|
||||
b.AddFiles("content/p2.md", "---\ntitle: p2\n---").Build()
|
||||
b.AssertFileContent("public/index.html", "p1|p2|") // this test passes, which doesn't match reality
|
||||
}
|
||||
|
||||
func TestRebuildHomeThenPageIssue12436(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.com"
|
||||
disableKinds = ['sitemap','taxonomy','term']
|
||||
disableLiveReload = true
|
||||
-- layouts/_default/list.html --
|
||||
{{ .Content }}
|
||||
-- layouts/_default/single.html --
|
||||
{{ .Content }}
|
||||
-- content/_index.md --
|
||||
---
|
||||
title: home
|
||||
---
|
||||
home-content|
|
||||
-- content/p1/index.md --
|
||||
---
|
||||
title: p1
|
||||
---
|
||||
p1-content|
|
||||
`
|
||||
|
||||
b := TestRunning(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", "home-content|")
|
||||
b.AssertFileContent("public/p1/index.html", "p1-content|")
|
||||
b.AssertRenderCountPage(3)
|
||||
|
||||
b.EditFileReplaceAll("content/_index.md", "home-content", "home-content-foo").Build()
|
||||
b.AssertFileContent("public/index.html", "home-content-foo")
|
||||
b.AssertRenderCountPage(2) // Home page rss + html
|
||||
|
||||
b.EditFileReplaceAll("content/p1/index.md", "p1-content", "p1-content-foo").Build()
|
||||
b.AssertFileContent("public/p1/index.html", "p1-content-foo")
|
||||
}
|
||||
|
||||
@@ -201,6 +201,43 @@ Myshort Original.
|
||||
b.AssertFileContent("public/p1/index.html", "Edited")
|
||||
}
|
||||
|
||||
func TestRenderShortcodesEditSectionContentWithShortcodeInIncludedPageIssue12458(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableLiveReload = true
|
||||
disableKinds = ["home", "taxonomy", "term", "rss", "sitemap", "robotsTXT", "404"]
|
||||
-- content/mysection/_index.md --
|
||||
---
|
||||
title: "My Section"
|
||||
---
|
||||
## p1-h1
|
||||
{{% include "p2" %}}
|
||||
-- content/mysection/p2.md --
|
||||
---
|
||||
title: "p2"
|
||||
---
|
||||
### Original
|
||||
{{% myshort %}}
|
||||
-- layouts/shortcodes/include.html --
|
||||
{{ $p := .Page.GetPage (.Get 0) }}
|
||||
{{ $p.RenderShortcodes }}
|
||||
-- layouts/shortcodes/myshort.html --
|
||||
Myshort Original.
|
||||
-- layouts/_default/list.html --
|
||||
{{ .Content }}
|
||||
|
||||
|
||||
|
||||
`
|
||||
b := TestRunning(t, files)
|
||||
|
||||
b.AssertFileContent("public/mysection/index.html", "p1-h1")
|
||||
b.EditFileReplaceAll("content/mysection/_index.md", "p1-h1", "p1-h1 Edited").Build()
|
||||
b.AssertFileContent("public/mysection/index.html", "p1-h1 Edited")
|
||||
}
|
||||
|
||||
func TestRenderShortcodesNestedPageContextIssue12356(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
+2
-2
@@ -123,14 +123,14 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
|
||||
HandlerPost: logHookLast,
|
||||
Stdout: cfg.LogOut,
|
||||
Stderr: cfg.LogOut,
|
||||
StoreErrors: conf.Running(),
|
||||
StoreErrors: conf.Watching(),
|
||||
SuppressStatements: conf.IgnoredLogs(),
|
||||
}
|
||||
logger = loggers.New(logOpts)
|
||||
|
||||
}
|
||||
|
||||
memCache := dynacache.New(dynacache.Options{Running: conf.Running(), Log: logger})
|
||||
memCache := dynacache.New(dynacache.Options{Watching: conf.Watching(), Log: logger})
|
||||
|
||||
firstSiteDeps := &deps.Deps{
|
||||
Fs: cfg.Fs,
|
||||
|
||||
+5
-2
@@ -1,7 +1,10 @@
|
||||
# Release env.
|
||||
# These will be replaced by script before release.
|
||||
HUGORELEASER_TAG=v0.125.1
|
||||
HUGORELEASER_COMMITISH=68c5ad638c2072969e47262926b912e80fd71a77
|
||||
HUGORELEASER_TAG=v0.125.6
|
||||
HUGORELEASER_COMMITISH=69ede10edcd539380914bbee58d4d32953dd8b43
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -225,9 +225,6 @@ type PageMetaProvider interface {
|
||||
// to the source of this Page. It will be relative to any content root.
|
||||
Path() string
|
||||
|
||||
// This is for internal use only.
|
||||
PathInfo() *paths.Path
|
||||
|
||||
// The slug, typically defined in front matter.
|
||||
Slug() string
|
||||
|
||||
@@ -253,6 +250,12 @@ type PageMetaProvider interface {
|
||||
Weight() int
|
||||
}
|
||||
|
||||
// PageMetaInternalProvider provides internal page metadata.
|
||||
type PageMetaInternalProvider interface {
|
||||
// This is for internal use only.
|
||||
PathInfo() *paths.Path
|
||||
}
|
||||
|
||||
// PageRenderProvider provides a way for a Page to render content.
|
||||
type PageRenderProvider interface {
|
||||
// Render renders the given layout with this Page as context.
|
||||
@@ -273,6 +276,7 @@ type PageWithoutContent interface {
|
||||
RenderShortcodesProvider
|
||||
resource.Resource
|
||||
PageMetaProvider
|
||||
PageMetaInternalProvider
|
||||
resource.LanguageProvider
|
||||
|
||||
// For pages backed by a file.
|
||||
|
||||
@@ -17,9 +17,8 @@ package page
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MarshalPageToJSON(p Page) ([]byte, error) {
|
||||
@@ -39,7 +38,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
||||
isNode := p.IsNode()
|
||||
isPage := p.IsPage()
|
||||
path := p.Path()
|
||||
pathc := p.Path()
|
||||
slug := p.Slug()
|
||||
lang := p.Lang()
|
||||
isSection := p.IsSection()
|
||||
@@ -65,7 +63,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
||||
IsNode bool
|
||||
IsPage bool
|
||||
Path string
|
||||
Pathc string
|
||||
Slug string
|
||||
Lang string
|
||||
IsSection bool
|
||||
@@ -90,7 +87,6 @@ func MarshalPageToJSON(p Page) ([]byte, error) {
|
||||
IsNode: isNode,
|
||||
IsPage: isPage,
|
||||
Path: path,
|
||||
Pathc: pathc,
|
||||
Slug: slug,
|
||||
Lang: lang,
|
||||
IsSection: isSection,
|
||||
|
||||
+10
-7
@@ -296,16 +296,19 @@ type hashProvider interface {
|
||||
hash() string
|
||||
}
|
||||
|
||||
var _ resource.StaleInfo = (*StaleValue[any])(nil)
|
||||
|
||||
type StaleValue[V any] struct {
|
||||
// The value.
|
||||
Value V
|
||||
|
||||
// IsStaleFunc reports whether the value is stale.
|
||||
IsStaleFunc func() bool
|
||||
// StaleVersionFunc reports the current version of the value.
|
||||
// This always starts out at 0 and get incremented on staleness.
|
||||
StaleVersionFunc func() uint32
|
||||
}
|
||||
|
||||
func (s *StaleValue[V]) IsStale() bool {
|
||||
return s.IsStaleFunc()
|
||||
func (s *StaleValue[V]) StaleVersion() uint32 {
|
||||
return s.StaleVersionFunc()
|
||||
}
|
||||
|
||||
type AtomicStaler struct {
|
||||
@@ -313,11 +316,11 @@ type AtomicStaler struct {
|
||||
}
|
||||
|
||||
func (s *AtomicStaler) MarkStale() {
|
||||
atomic.StoreUint32(&s.stale, 1)
|
||||
atomic.AddUint32(&s.stale, 1)
|
||||
}
|
||||
|
||||
func (s *AtomicStaler) IsStale() bool {
|
||||
return atomic.LoadUint32(&(s.stale)) > 0
|
||||
func (s *AtomicStaler) StaleVersion() uint32 {
|
||||
return atomic.LoadUint32(&(s.stale))
|
||||
}
|
||||
|
||||
// For internal use.
|
||||
|
||||
@@ -233,17 +233,27 @@ type StaleMarker interface {
|
||||
|
||||
// StaleInfo tells if a resource is marked as stale.
|
||||
type StaleInfo interface {
|
||||
IsStale() bool
|
||||
StaleVersion() uint32
|
||||
}
|
||||
|
||||
// IsStaleAny reports whether any of the os is marked as stale.
|
||||
func IsStaleAny(os ...any) bool {
|
||||
for _, o := range os {
|
||||
if s, ok := o.(StaleInfo); ok && s.IsStale() {
|
||||
return true
|
||||
// StaleVersion returns the StaleVersion for the given os,
|
||||
// or 0 if not set.
|
||||
func StaleVersion(os any) uint32 {
|
||||
if s, ok := os.(StaleInfo); ok {
|
||||
return s.StaleVersion()
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// StaleVersionSum calculates the sum of the StaleVersionSum for the given oss.
|
||||
func StaleVersionSum(oss ...any) uint32 {
|
||||
var version uint32
|
||||
for _, o := range oss {
|
||||
if s, ok := o.(StaleInfo); ok && s.StaleVersion() > 0 {
|
||||
version += s.StaleVersion()
|
||||
}
|
||||
}
|
||||
return false
|
||||
return version
|
||||
}
|
||||
|
||||
// MarkStale will mark any of the oses as stale, if possible.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2021 The Hugo Authors. All rights reserved.
|
||||
// Copyright 2024 The Hugo Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -328,6 +328,7 @@ Styles: {{ $r.RelPermalink }}
|
||||
b.AssertFileContent("public/index.html", "Styles: /scss/main.css")
|
||||
}
|
||||
|
||||
// Issue #1239.
|
||||
func TestRebuildAssetGetMatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !scss.Supports() {
|
||||
@@ -358,3 +359,61 @@ T1: {{ $r.Content }}
|
||||
|
||||
b.AssertFileContent("public/index.html", `color: blue`)
|
||||
}
|
||||
|
||||
func TestRebuildAssetMatchIssue12456(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !scss.Supports() {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ["term", "taxonomy", "section", "page"]
|
||||
disableLiveReload = true
|
||||
-- assets/a.scss --
|
||||
h1 {
|
||||
color: red;
|
||||
}
|
||||
-- assets/dir/b.scss --
|
||||
h2 {
|
||||
color: blue;
|
||||
}
|
||||
-- assets/dir/c.scss --
|
||||
h3 {
|
||||
color: green;
|
||||
}
|
||||
-- layouts/index.html --
|
||||
{{ $a := slice (resources.Get "a.scss") }}
|
||||
{{ $b := resources.Match "dir/*.scss" }}
|
||||
|
||||
{{/* Add styles in a specific order. */}}
|
||||
{{ $styles := slice $a $b }}
|
||||
|
||||
{{ $stylesheets := slice }}
|
||||
{{ range $styles }}
|
||||
{{ $stylesheets = $stylesheets | collections.Append . }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ range $stylesheets }}
|
||||
{{ with . | resources.ToCSS | fingerprint }}
|
||||
<link as="style" href="{{ .RelPermalink }}" rel="preload stylesheet">
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
b := hugolib.NewIntegrationTestBuilder(
|
||||
hugolib.IntegrationTestConfig{
|
||||
T: t,
|
||||
TxtarString: files,
|
||||
NeedsOsFS: true,
|
||||
Running: true,
|
||||
// LogLevel: logg.LevelTrace,
|
||||
}).Build()
|
||||
|
||||
b.AssertFileContent("public/index.html", `b.60a9f3bdc189ee8a857afd5b7e1b93ad1644de0873761a7c9bc84f781a821942.css`)
|
||||
|
||||
b.EditFiles("assets/dir/b.scss", `h2 { color: orange; }`).Build()
|
||||
|
||||
b.AssertFileContent("public/index.html", `b.46b2d77c7ffe37ee191678f72df991ecb1319f849957151654362f09b0ef467f.css`)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ var (
|
||||
_ resource.ReadSeekCloserResource = (*resourceAdapter)(nil)
|
||||
_ resource.Resource = (*resourceAdapter)(nil)
|
||||
_ resource.Staler = (*resourceAdapterInner)(nil)
|
||||
_ identity.IdentityGroupProvider = (*resourceAdapterInner)(nil)
|
||||
_ resource.Source = (*resourceAdapter)(nil)
|
||||
_ resource.Identifier = (*resourceAdapter)(nil)
|
||||
_ resource.ResourceNameTitleProvider = (*resourceAdapter)(nil)
|
||||
@@ -657,8 +658,13 @@ type resourceAdapterInner struct {
|
||||
*publishOnce
|
||||
}
|
||||
|
||||
func (r *resourceAdapterInner) IsStale() bool {
|
||||
return r.Staler.IsStale() || r.target.IsStale()
|
||||
func (r *resourceAdapterInner) GetIdentityGroup() identity.Identity {
|
||||
return r.target.GetIdentityGroup()
|
||||
}
|
||||
|
||||
func (r *resourceAdapterInner) StaleVersion() uint32 {
|
||||
// Both of these are incremented on change.
|
||||
return r.Staler.StaleVersion() + r.target.StaleVersion()
|
||||
}
|
||||
|
||||
type resourceTransformations struct {
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
<meta property="og:site_name" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- with or .Title site.Title site.Params.title | plainify}}
|
||||
{{- with or .Title site.Title site.Params.title | plainify }}
|
||||
<meta property="og:title" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
{{- with or .Description .Summary site.Params.description | plainify }}
|
||||
{{- with or .Description .Summary site.Params.description | plainify | htmlUnescape | chomp }}
|
||||
<meta property="og:description" content="{{ . }}">
|
||||
{{- end }}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
{{- if .IsPage }}
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="article:section" content="{{ .Section }}">
|
||||
{{- with .Section }}
|
||||
<meta property="article:section" content="{{ . }}">
|
||||
{{- end }}
|
||||
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
|
||||
{{- with .PublishDate }}
|
||||
<meta property="article:published_time" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}>
|
||||
|
||||
@@ -71,7 +71,7 @@ var (
|
||||
)
|
||||
|
||||
type templateExecHelper struct {
|
||||
running bool // whether we're in server mode.
|
||||
watching bool // whether we're in server/watch mode.
|
||||
site reflect.Value
|
||||
siteParams reflect.Value
|
||||
funcs map[string]reflect.Value
|
||||
@@ -95,7 +95,7 @@ func (t *templateExecHelper) GetFunc(ctx context.Context, tmpl texttemplate.Prep
|
||||
}
|
||||
|
||||
func (t *templateExecHelper) Init(ctx context.Context, tmpl texttemplate.Preparer) {
|
||||
if t.running {
|
||||
if t.watching {
|
||||
_, ok := tmpl.(identity.IdentityProvider)
|
||||
if ok {
|
||||
t.trackDependencies(ctx, tmpl, "", reflect.Value{})
|
||||
@@ -129,7 +129,7 @@ func (t *templateExecHelper) GetMethod(ctx context.Context, tmpl texttemplate.Pr
|
||||
name = "MainSections"
|
||||
}
|
||||
|
||||
if t.running {
|
||||
if t.watching {
|
||||
ctx = t.trackDependencies(ctx, tmpl, name, receiver)
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func (t *templateExecHelper) GetMethod(ctx context.Context, tmpl texttemplate.Pr
|
||||
}
|
||||
|
||||
func (t *templateExecHelper) OnCalled(ctx context.Context, tmpl texttemplate.Preparer, name string, args []reflect.Value, result reflect.Value) {
|
||||
if !t.running {
|
||||
if !t.watching {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ func newTemplateExecuter(d *deps.Deps) (texttemplate.Executer, map[string]reflec
|
||||
}
|
||||
|
||||
exeHelper := &templateExecHelper{
|
||||
running: d.Conf.Running(),
|
||||
watching: d.Conf.Watching(),
|
||||
funcs: funcsv,
|
||||
site: reflect.ValueOf(d.Site),
|
||||
siteParams: reflect.ValueOf(d.Site.Params()),
|
||||
|
||||
@@ -305,3 +305,109 @@ title: p2
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n <url>\n <loc>/p2/</loc>\n </url>\n</urlset>\n",
|
||||
)
|
||||
}
|
||||
|
||||
// Issue 12418
|
||||
func TestOpengraph(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
capitalizeListTitles = false
|
||||
disableKinds = ['rss','sitemap']
|
||||
languageCode = 'en-US'
|
||||
[markup.goldmark.renderer]
|
||||
unsafe = true
|
||||
[params]
|
||||
description = "m <em>n</em> and **o** can't."
|
||||
[params.social]
|
||||
facebook_admin = 'foo'
|
||||
[taxonomies]
|
||||
series = 'series'
|
||||
tag = 'tags'
|
||||
-- layouts/_default/list.html --
|
||||
{{ template "_internal/opengraph.html" . }}
|
||||
-- layouts/_default/single.html --
|
||||
{{ template "_internal/opengraph.html" . }}
|
||||
-- content/s1/p1.md --
|
||||
---
|
||||
title: p1
|
||||
date: 2024-04-24T08:00:00-07:00
|
||||
lastmod: 2024-04-24T11:00:00-07:00
|
||||
images: [a.jpg,b.jpg]
|
||||
audio: [c.mp3,d.mp3]
|
||||
videos: [e.mp4,f.mp4]
|
||||
series: [series-1]
|
||||
tags: [t1,t2]
|
||||
---
|
||||
a <em>b</em> and **c** can't.
|
||||
-- content/s1/p2.md --
|
||||
---
|
||||
title: p2
|
||||
series: [series-1]
|
||||
---
|
||||
d <em>e</em> and **f** can't.
|
||||
<!--more-->
|
||||
-- content/s1/p3.md --
|
||||
---
|
||||
title: p3
|
||||
series: [series-1]
|
||||
summary: g <em>h</em> and **i** can't.
|
||||
---
|
||||
-- content/s1/p4.md --
|
||||
---
|
||||
title: p4
|
||||
series: [series-1]
|
||||
description: j <em>k</em> and **l** can't.
|
||||
---
|
||||
-- content/s1/p5.md --
|
||||
---
|
||||
title: p5
|
||||
series: [series-1]
|
||||
---
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/s1/p1/index.html", `
|
||||
<meta property="og:url" content="/s1/p1/">
|
||||
<meta property="og:title" content="p1">
|
||||
<meta property="og:description" content="a b and c can’t.">
|
||||
<meta property="og:locale" content="en-US">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="article:section" content="s1">
|
||||
<meta property="article:published_time" content="2024-04-24T08:00:00-07:00">
|
||||
<meta property="article:modified_time" content="2024-04-24T11:00:00-07:00">
|
||||
<meta property="article:tag" content="t1">
|
||||
<meta property="article:tag" content="t2">
|
||||
<meta property="og:image" content="/a.jpg">
|
||||
<meta property="og:image" content="/b.jpg">
|
||||
<meta property="og:audio" content="/c.mp3">
|
||||
<meta property="og:audio" content="/d.mp3">
|
||||
<meta property="og:video" content="/e.mp4">
|
||||
<meta property="og:video" content="/f.mp4">
|
||||
<meta property="og:see_also" content="/s1/p2/">
|
||||
<meta property="og:see_also" content="/s1/p3/">
|
||||
<meta property="og:see_also" content="/s1/p4/">
|
||||
<meta property="og:see_also" content="/s1/p5/">
|
||||
<meta property="fb:admins" content="foo">
|
||||
`,
|
||||
)
|
||||
|
||||
b.AssertFileContent("public/s1/p2/index.html",
|
||||
`<meta property="og:description" content="d e and f can’t.">`,
|
||||
)
|
||||
|
||||
b.AssertFileContent("public/s1/p3/index.html",
|
||||
`<meta property="og:description" content="g h and i can’t.">`,
|
||||
)
|
||||
|
||||
// The markdown is intentionally not rendered to HTML.
|
||||
b.AssertFileContent("public/s1/p4/index.html",
|
||||
`<meta property="og:description" content="j k and **l** can't.">`,
|
||||
)
|
||||
|
||||
// The markdown is intentionally not rendered to HTML.
|
||||
b.AssertFileContent("public/s1/p5/index.html",
|
||||
`<meta property="og:description" content="m n and **o** can't.">`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
|
||||
|
||||
return &resources.StaleValue[any]{
|
||||
Value: v,
|
||||
IsStaleFunc: func() bool {
|
||||
return resource.IsStaleAny(r)
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return resource.StaleVersion(r)
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
@@ -132,8 +132,8 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
|
||||
|
||||
return &resources.StaleValue[any]{
|
||||
Value: v,
|
||||
IsStaleFunc: func() bool {
|
||||
return false
|
||||
StaleVersionFunc: func() uint32 {
|
||||
return 0
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user