Make sure that unreferenced but changed bundle resources gets republished

Fixes #13748
This commit is contained in:
Bjørn Erik Pedersen
2025-05-28 09:18:16 +02:00
parent 13e1617557
commit 766a2e7868
8 changed files with 77 additions and 38 deletions

View File

@@ -24,6 +24,7 @@ import (
"sync/atomic"
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/lazy"
"github.com/gohugoio/hugo/resources/internal"
"github.com/gohugoio/hugo/common/hashing"
@@ -54,6 +55,7 @@ var (
_ identity.DependencyManagerProvider = (*genericResource)(nil)
_ identity.Identity = (*genericResource)(nil)
_ fileInfo = (*genericResource)(nil)
_ isPublishedProvider = (*genericResource)(nil)
)
type ResourceSourceDescriptor struct {
@@ -242,6 +244,7 @@ type baseResourceInternal interface {
fileInfo
mediaTypeAssigner
targetPather
isPublishedProvider
ReadSeekCloser() (hugio.ReadSeekCloser, error)
@@ -355,7 +358,7 @@ func GetTestInfoForResource(r resource.Resource) GenericResourceTestInfo {
// genericResource represents a generic linkable resource.
type genericResource struct {
publishInit *sync.Once
publishInit *lazy.OnceMore
key string
keyInit *sync.Once
@@ -536,6 +539,10 @@ func (l *genericResource) Publish() error {
return err
}
func (l *genericResource) isPublished() bool {
return l.publishInit.Done()
}
func (l *genericResource) RelPermalink() string {
return l.spec.PathSpec.GetBasePath(false) + paths.PathEscape(l.paths.TargetLink())
}
@@ -629,7 +636,7 @@ func (rc *genericResource) cloneWithUpdates(u *transformationUpdate) (baseResour
}
func (l genericResource) clone() *genericResource {
l.publishInit = &sync.Once{}
l.publishInit = &lazy.OnceMore{}
l.keyInit = &sync.Once{}
return &l
}
@@ -643,6 +650,10 @@ type targetPather interface {
TargetPath() string
}
type isPublishedProvider interface {
isPublished() bool
}
type resourceHash struct {
value uint64
size int64
@@ -702,6 +713,11 @@ func InternalResourceSourcePathBestEffort(r resource.Resource) string {
return InternalResourceTargetPath(r)
}
// isPublished returns true if the resource is published.
func IsPublished(r resource.Resource) bool {
return r.(isPublishedProvider).isPublished()
}
type targetPathProvider interface {
// targetPath is the relative path to this resource.
// In most cases this will be the same as the RelPermalink(),