resources

package
v0.125.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 50 Imported by: 33

Documentation

Overview

Package resources contains Resource related types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneWithMetadataIfNeeded added in v0.123.0

func CloneWithMetadataIfNeeded(m []map[string]any, r resource.Resource) resource.Resource

func Copy added in v0.100.0

func Copy(r resource.Resource, targetPath string) resource.Resource

Copy copies r to the targetPath given.

func NewErrorResource added in v0.90.1

func NewErrorResource(err resource.ResourceError) resource.Resource

NewErrorResource wraps err in a Resource where all but the Err method will panic.

Types

type AtomicStaler added in v0.123.0

type AtomicStaler struct {
	// contains filtered or unexported fields
}

func (*AtomicStaler) IsStale added in v0.123.0

func (s *AtomicStaler) IsStale() bool

func (*AtomicStaler) MarkStale added in v0.123.0

func (s *AtomicStaler) MarkStale()

type GenericResourceTestInfo added in v0.123.0

type GenericResourceTestInfo struct {
	Paths internal.ResourcePaths
}

For internal use.

func GetTestInfoForResource added in v0.123.0

func GetTestInfoForResource(r resource.Resource) GenericResourceTestInfo

For internal use.

type ImageCache added in v0.112.4

type ImageCache struct {
	// contains filtered or unexported fields
}

ImageCache is a cache for image resources. The backing caches are shared between all sites.

type PostBuildAssets added in v0.78.0

type PostBuildAssets struct {
	PostProcessResources map[string]postpub.PostPublishedResource
	JSConfigBuilder      *jsconfig.Builder
	// contains filtered or unexported fields
}

type ResourceCache

type ResourceCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ResourceCache) Get added in v0.123.0

func (*ResourceCache) GetOrCreate

func (c *ResourceCache) GetOrCreate(key string, f func() (resource.Resource, error)) (resource.Resource, error)

func (*ResourceCache) GetOrCreateResources added in v0.57.0

func (c *ResourceCache) GetOrCreateResources(key string, f func() (resource.Resources, error)) (resource.Resources, error)

type ResourceSourceDescriptor

type ResourceSourceDescriptor struct {
	// The source content.
	OpenReadSeekCloser hugio.OpenReadSeekCloser

	// The canonical source path.
	Path *paths.Path

	// The normalized name of the resource.
	NameNormalized string

	// The name of the resource as it was read from the source.
	NameOriginal string

	// Any base paths prepended to the target path. This will also typically be the
	// language code, but setting it here means that it should not have any effect on
	// the permalink.
	// This may be several values. In multihost mode we may publish the same resources to
	// multiple targets.
	TargetBasePaths []string

	TargetPath           string
	BasePathRelPermalink string
	BasePathTargetPath   string

	// The Data to associate with this resource.
	Data map[string]any

	// Delay publishing until either Permalink or RelPermalink is called. Maybe never.
	LazyPublish bool

	// Set when its known up front, else it's resolved from the target filename.
	MediaType media.Type

	// Used to track dependencies (e.g. imports). May be nil if that's of no concern.
	DependencyManager identity.Manager

	// A shared identity for this resource and all its clones.
	// If this is not set, an Identity is created.
	GroupIdentity identity.Identity
}

type ResourceTransformation

type ResourceTransformation interface {
	Key() internal.ResourceTransformationKey
	Transform(ctx *ResourceTransformationCtx) error
}

ResourceTransformation is the interface that a resource transformation step needs to implement.

func NewFeatureNotAvailableTransformer added in v0.65.0

func NewFeatureNotAvailableTransformer(key string, elements ...any) ResourceTransformation

type ResourceTransformationCtx

type ResourceTransformationCtx struct {
	// The context that started the transformation.
	Ctx context.Context

	// The dependency manager to use for dependency tracking.
	DependencyManager identity.Manager

	// The content to transform.
	From io.Reader

	// The target of content transformation.
	// The current implementation requires that r is written to w
	// even if no transformation is performed.
	To io.Writer

	// This is the relative path to the original source. Unix styled slashes.
	SourcePath string

	// This is the relative target path to the resource. Unix styled slashes.
	InPath string

	// The relative target path to the transformed resource. Unix styled slashes.
	OutPath string

	// The input media type
	InMediaType media.Type

	// The media type of the transformed resource.
	OutMediaType media.Type

	// Data data can be set on the transformed Resource. Not that this need
	// to be simple types, as it needs to be serialized to JSON and back.
	Data map[string]any

	// This is used to publish additional artifacts, e.g. source maps.
	// We may improve this.
	OpenResourcePublisher func(relTargetPath string) (io.WriteCloser, error)
}

func (*ResourceTransformationCtx) AddOutPathIdentifier

func (ctx *ResourceTransformationCtx) AddOutPathIdentifier(identifier string)

AddOutPathIdentifier transforming InPath to OutPath adding an identifier, eg '.min' before any extension.

func (*ResourceTransformationCtx) PublishSourceMap

func (ctx *ResourceTransformationCtx) PublishSourceMap(content string) error

PublishSourceMap writes the content to the target folder of the main resource with the ".map" extension added.

func (*ResourceTransformationCtx) ReplaceOutPathExtension

func (ctx *ResourceTransformationCtx) ReplaceOutPathExtension(newExt string)

ReplaceOutPathExtension transforming InPath to OutPath replacing the file extension, e.g. ".scss"

type ResourceTransformer added in v0.58.0

type ResourceTransformer interface {
	resource.Resource
	Transformer
}

type Spec

type Spec struct {
	*helpers.PathSpec

	Logger      loggers.Logger
	ErrorSender herrors.ErrorSender

	TextTemplates tpl.TemplateParseFinder

	Permalinks page.PermalinkExpander

	ImageCache *ImageCache

	ExecHelper *hexec.Exec

	*SpecCommon
	// contains filtered or unexported fields
}

func NewSpec

func NewSpec(
	s *helpers.PathSpec,
	common *SpecCommon,
	fileCaches filecache.Caches,
	memCache *dynacache.Cache,
	incr identity.Incrementer,
	logger loggers.Logger,
	errorHandler herrors.ErrorSender,
	execHelper *hexec.Exec,
) (*Spec, error)

func (*Spec) BuildConfig added in v0.66.0

func (r *Spec) BuildConfig() config.BuildConfig

func (*Spec) MediaTypes

func (r *Spec) MediaTypes() media.Types

func (*Spec) NewResource added in v0.123.0

func (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, error)

NewResource creates a new Resource from the given ResourceSourceDescriptor.

func (*Spec) OutputFormats

func (r *Spec) OutputFormats() output.Formats

func (*Spec) PostProcess added in v0.69.0

func (spec *Spec) PostProcess(r resource.Resource) (postpub.PostPublishedResource, error)

PostProcess wraps the given Resource for later processing.

func (*Spec) String added in v0.58.0

func (s *Spec) String() string

type SpecCommon added in v0.112.0

type SpecCommon struct {
	ResourceCache *ResourceCache
	FileCaches    filecache.Caches

	// Assets used after the build is done.
	// This is shared between all sites.
	*PostBuildAssets
	// contains filtered or unexported fields
}

The parts of Spec that's common for all sites.

type StaleValue added in v0.123.0

type StaleValue[V any] struct {
	// The value.
	Value V

	// IsStaleFunc reports whether the value is stale.
	IsStaleFunc func() bool
}

func (*StaleValue[V]) IsStale added in v0.123.0

func (s *StaleValue[V]) IsStale() bool

type Transformer added in v0.58.0

type Transformer interface {
	Transform(...ResourceTransformation) (ResourceTransformer, error)
	TransformWithContext(context.Context, ...ResourceTransformation) (ResourceTransformer, error)
}

Directories

Path Synopsis
Package images provides template functions for manipulating images.
Package images provides template functions for manipulating images.
Package page contains the core interfaces and types for the Page resource, a core component in Hugo.
Package page contains the core interfaces and types for the Page resource, a core component in Hugo.
Package resource contains Resource related types.
Package resource contains Resource related types.
resource_factories
bundler
Package bundler contains functions for concatenation etc.
Package bundler contains functions for concatenation etc.
create
Package create contains functions for to create Resource objects.
Package create contains functions for to create Resource objects.
resource_transformers
js
templates
Package templates contains functions for template processing of Resource objects.
Package templates contains functions for template processing of Resource objects.
tocss/dartsass
Package dartsass integrates with the Dart Sass Embedded protocol to transpile SCSS/SASS.
Package dartsass integrates with the Dart Sass Embedded protocol to transpile SCSS/SASS.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL