mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-02 22:52:51 +02:00
Make sure that unreferenced but changed bundle resources gets republished
Fixes #13748
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -1310,7 +1309,6 @@ func (h *HugoSites) resolveAndResetDependententPageOutputs(ctx context.Context,
|
||||
}
|
||||
|
||||
po.renderState = 0
|
||||
po.p.resourcesPublishInit = &sync.Once{}
|
||||
if r == identity.FinderFoundOneOfMany || po.f.Name == output.HTTPStatus404HTMLFormat.Name {
|
||||
// Will force a re-render even in fast render mode.
|
||||
po.renderOnce = false
|
||||
|
@@ -905,7 +905,6 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
|
||||
handleChange := func(pathInfo *paths.Path, delete, isDir bool) {
|
||||
switch pathInfo.Component() {
|
||||
case files.ComponentFolderContent:
|
||||
logger.Println("Source changed", pathInfo.Path())
|
||||
isContentDataFile := pathInfo.IsContentData()
|
||||
if !isContentDataFile {
|
||||
if ids := h.pageTrees.collectAndMarkStaleIdentities(pathInfo); len(ids) > 0 {
|
||||
|
@@ -19,7 +19,6 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
@@ -29,6 +28,7 @@ import (
|
||||
"github.com/gohugoio/hugo/media"
|
||||
"github.com/gohugoio/hugo/output"
|
||||
"github.com/gohugoio/hugo/related"
|
||||
"github.com/gohugoio/hugo/resources"
|
||||
"github.com/gohugoio/hugo/tpl/tplimpl"
|
||||
"github.com/spf13/afero"
|
||||
|
||||
@@ -110,8 +110,7 @@ type pageState struct {
|
||||
*pageCommon
|
||||
|
||||
resource.Staler
|
||||
dependencyManager identity.Manager
|
||||
resourcesPublishInit *sync.Once
|
||||
dependencyManager identity.Manager
|
||||
}
|
||||
|
||||
func (p *pageState) incrPageOutputTemplateVariation() {
|
||||
@@ -522,39 +521,41 @@ func (p *pageState) initPage() error {
|
||||
}
|
||||
|
||||
func (p *pageState) renderResources() error {
|
||||
var initErr error
|
||||
for _, r := range p.Resources() {
|
||||
|
||||
p.resourcesPublishInit.Do(func() {
|
||||
for _, r := range p.Resources() {
|
||||
if _, ok := r.(page.Page); ok {
|
||||
if _, ok := r.(page.Page); ok {
|
||||
if p.s.h.buildCounter.Load() == 0 {
|
||||
// Pages gets rendered with the owning page but we count them here.
|
||||
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Pages)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, isWrapper := r.(resource.ResourceWrapper); isWrapper {
|
||||
// Skip resources that are wrapped.
|
||||
// These gets published on its own.
|
||||
continue
|
||||
}
|
||||
|
||||
src, ok := r.(resource.Source)
|
||||
if !ok {
|
||||
initErr = fmt.Errorf("resource %T does not support resource.Source", r)
|
||||
return
|
||||
}
|
||||
|
||||
if err := src.Publish(); err != nil {
|
||||
if !herrors.IsNotExist(err) {
|
||||
p.s.Log.Errorf("Failed to publish Resource for page %q: %s", p.pathOrTitle(), err)
|
||||
}
|
||||
} else {
|
||||
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Files)
|
||||
}
|
||||
continue
|
||||
}
|
||||
})
|
||||
|
||||
return initErr
|
||||
if resources.IsPublished(r) {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, isWrapper := r.(resource.ResourceWrapper); isWrapper {
|
||||
// Skip resources that are wrapped.
|
||||
// These gets published on its own.
|
||||
continue
|
||||
}
|
||||
|
||||
src, ok := r.(resource.Source)
|
||||
if !ok {
|
||||
return fmt.Errorf("resource %T does not support resource.Source", r)
|
||||
}
|
||||
|
||||
if err := src.Publish(); err != nil {
|
||||
if !herrors.IsNotExist(err) {
|
||||
p.s.Log.Errorf("Failed to publish Resource for page %q: %s", p.pathOrTitle(), err)
|
||||
}
|
||||
} else {
|
||||
p.s.PathSpec.ProcessingStats.Incr(&p.s.PathSpec.ProcessingStats.Files)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pageState) AlternativeOutputFormats() page.OutputFormats {
|
||||
|
@@ -16,7 +16,6 @@ package hugolib
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs/files"
|
||||
@@ -190,7 +189,6 @@ func (h *HugoSites) doNewPage(m *pageMeta) (*pageState, *paths.Path, error) {
|
||||
pid: pid,
|
||||
pageOutput: nopPageOutput,
|
||||
pageOutputTemplateVariationsState: &atomic.Uint32{},
|
||||
resourcesPublishInit: &sync.Once{},
|
||||
Staler: m,
|
||||
dependencyManager: m.s.Conf.NewIdentityManager(m.Path()),
|
||||
pageCommon: &pageCommon{
|
||||
|
@@ -1946,3 +1946,23 @@ tags: ["tag1"]
|
||||
// But that is a harder problem to tackle.
|
||||
b.AssertFileContent("public/tags/index.html", "All. Tag1|Tag2|")
|
||||
}
|
||||
|
||||
func TestRebuildEditNonReferencedResourceIssue13748(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.com"
|
||||
disableLiveReload = true
|
||||
-- content/mybundle/index.md --
|
||||
-- content/mybundle/resource.txt --
|
||||
This is a resource file.
|
||||
-- layouts/all.html --
|
||||
All.
|
||||
`
|
||||
b := TestRunning(t, files)
|
||||
|
||||
b.AssertFileContent("public/mybundle/resource.txt", "This is a resource file.")
|
||||
b.EditFileReplaceAll("content/mybundle/resource.txt", "This is a resource file.", "This is an edited resource file.").Build()
|
||||
b.AssertFileContent("public/mybundle/resource.txt", "This is an edited resource file.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user