Fix rebuild with resources.Concat

Fixes #12017
This commit is contained in:
Bjørn Erik Pedersen
2024-02-09 13:52:36 +02:00
parent 21d9057dbf
commit 639073e4fe
18 changed files with 229 additions and 120 deletions

View File

@@ -93,8 +93,8 @@ func (r *resourceSource) GetIdentity() identity.Identity {
return r.path
}
func (r *resourceSource) ForEeachIdentity(f func(identity.Identity) bool) {
f(r.GetIdentity())
func (r *resourceSource) ForEeachIdentity(f func(identity.Identity) bool) bool {
return f(r.GetIdentity())
}
func (r *resourceSource) Path() string {
@@ -142,14 +142,15 @@ func (n resourceSources) GetIdentity() identity.Identity {
return nil
}
func (n resourceSources) ForEeachIdentity(f func(identity.Identity) bool) {
func (n resourceSources) ForEeachIdentity(f func(identity.Identity) bool) bool {
for _, r := range n {
if r != nil {
if f(r.GetIdentity()) {
return
return true
}
}
}
return false
}
func (cfg contentMapConfig) getTaxonomyConfig(s string) (v viewName) {

View File

@@ -605,12 +605,15 @@ func (n contentNodeIs) GetIdentity() identity.Identity {
return n[0].GetIdentity()
}
func (n contentNodeIs) ForEeachIdentity(f func(identity.Identity) bool) {
func (n contentNodeIs) ForEeachIdentity(f func(identity.Identity) bool) bool {
for _, nn := range n {
if nn != nil {
nn.ForEeachIdentity(f)
if nn.ForEeachIdentity(f) {
return true
}
}
}
return false
}
func (n contentNodeIs) resetBuildState() {
@@ -1151,7 +1154,7 @@ func (h *HugoSites) resolveAndResetDependententPageOutputs(ctx context.Context,
// First check the top level dependency manager.
for _, id := range changes {
checkedCounter.Add(1)
if r := depsFinder.Contains(id, p.dependencyManager, 100); r > identity.FinderFoundOneOfManyRepetition {
if r := depsFinder.Contains(id, p.dependencyManager, 2); r > identity.FinderFoundOneOfManyRepetition {
for _, po := range p.pageOutputs {
resetPo(po, r)
}
@@ -1167,7 +1170,7 @@ func (h *HugoSites) resolveAndResetDependententPageOutputs(ctx context.Context,
}
for _, id := range changes {
checkedCounter.Add(1)
if r := depsFinder.Contains(id, po.dependencyManagerOutput, 2); r > identity.FinderFoundOneOfManyRepetition {
if r := depsFinder.Contains(id, po.dependencyManagerOutput, 50); r > identity.FinderFoundOneOfManyRepetition {
resetPo(po, r)
continue OUTPUTS
}

View File

@@ -120,8 +120,8 @@ func (p *pageState) GetIdentity() identity.Identity {
return p
}
func (p *pageState) ForEeachIdentity(f func(identity.Identity) bool) {
f(p)
func (p *pageState) ForEeachIdentity(f func(identity.Identity) bool) bool {
return f(p)
}
func (p *pageState) GetDependencyManager() identity.Manager {

View File

@@ -20,7 +20,6 @@ import (
"sync/atomic"
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/common/maps"
@@ -160,12 +159,6 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
return nil, nil
}
var dependencyManager identity.Manager = identity.NopManager
if m.s.conf.Internal.Watch {
dependencyManager = identity.NewManager(m.Path())
}
// Parse the rest of the page content.
m.content, err = m.newCachedContent(h, pi)
if err != nil {
@@ -178,7 +171,7 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
pageOutputTemplateVariationsState: &atomic.Uint32{},
resourcesPublishInit: &sync.Once{},
Staler: m,
dependencyManager: dependencyManager,
dependencyManager: m.s.Conf.NewIdentityManager(m.Path()),
pageCommon: &pageCommon{
FileProvider: m,
AuthorProvider: m,

View File

@@ -51,11 +51,6 @@ func newPageOutput(
})
}
var dependencyManager identity.Manager = identity.NopManager
if ps.s.conf.Internal.Watch {
dependencyManager = identity.NewManager(ps.Path() + "/" + f.Name)
}
providers := struct {
page.PaginatorProvider
resource.ResourceLinksProvider
@@ -75,7 +70,7 @@ func newPageOutput(
TableOfContentsProvider: page.NopPage,
render: render,
paginator: pag,
dependencyManagerOutput: dependencyManager,
dependencyManagerOutput: ps.s.Conf.NewIdentityManager((ps.Path() + "/" + f.Name)),
}
return po

View File

@@ -1131,7 +1131,7 @@ Single.
Running: true,
NeedsOsFS: true,
NeedsNpmInstall: true,
// LogLevel: logg.LevelTrace,
// LogLevel: logg.LevelDebug,
},
).Build()
@@ -1261,3 +1261,35 @@ func BenchmarkRebuildContentFileChange(b *testing.B) {
// fmt.Println(bb.LogString())
}
}
func TestRebuildConcat(t *testing.T) {
files := `
-- hugo.toml --
baseURL = "https://example.com"
disableLiveReload = true
disableKinds = ["taxonomy", "term", "sitemap", "robotsTXT", "404", "rss"]
-- assets/a.css --
a
-- assets/b.css --
b
-- assets/c.css --
c
-- assets/common/c1.css --
c1
-- assets/common/c2.css --
c2
-- layouts/index.html --
{{ $a := resources.Get "a.css" }}
{{ $b := resources.Get "b.css" }}
{{ $common := resources.Match "common/*.css" | resources.Concat "common.css" | minify }}
{{ $ab := slice $a $b $common | resources.Concat "ab.css" }}
all: {{ $ab.RelPermalink }}
`
b := TestRunning(t, files)
b.AssertFileContent("public/ab.css", "abc1c2")
b.EditFileReplaceAll("assets/common/c2.css", "c2", "c2 edited").Build()
b.AssertFileContent("public/ab.css", "abc1c2 edited")
b.AddFiles("assets/common/c3.css", "c3").Build()
b.AssertFileContent("public/ab.css", "abc1c2 editedc3")
}