diff options
Diffstat (limited to 'resources/resource.go')
-rw-r--r-- | resources/resource.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/resources/resource.go b/resources/resource.go index 6ef9bdae0..f6e5b9d73 100644 --- a/resources/resource.go +++ b/resources/resource.go @@ -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(), |