resources

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: Apache-2.0 Imports: 47 Imported by: 33

Documentation

Index

Constants

View Source
const (
	CACHE_CLEAR_ALL = "clear_all"
	CACHE_OTHER     = "other"
)

Variables

This section is empty.

Functions

func AssignMetadata

func AssignMetadata(metadata []map[string]interface{}, resources ...resource.Resource) error

AssignMetadata assigns the given metadata to those resources that supports updates and matching by wildcard given in `src` using `filepath.Match` with lower cased values. This assignment is additive, but the most specific match needs to be first. The `name` and `title` metadata field support shell-matched collection it got a match in. See https://golang.org/pkg/path/#Match

func ResourceCacheKey added in v0.57.0

func ResourceCacheKey(filename string) string

ResourceCacheKey converts the filename into the format used in the resource cache.

func ResourceKeyContainsAny added in v0.57.0

func ResourceKeyContainsAny(key string, partitions []string) bool

ResourceKeyContainsAny returns whether the key is a member of any of the given partitions.

This is used for resource cache invalidation.

func ResourceKeyPartitions added in v0.57.0

func ResourceKeyPartitions(filename string) []string

ResourceKeyPartitions resolves a ordered slice of partitions that is used to do resource cache invalidations.

We use the first directory path element and the extension, so:

a/b.json => "a", "json"
b.json => "json"

For some of the extensions we will also map to closely related types, e.g. "scss" will also return "sass".

Types

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) Contains

func (c *ResourceCache) Contains(key string) bool

func (*ResourceCache) DeleteMatches added in v0.78.0

func (c *ResourceCache) DeleteMatches(re *regexp.Regexp)

func (*ResourceCache) DeletePartitions

func (c *ResourceCache) DeletePartitions(partitions ...string)

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 {
	// TargetPaths is a callback to fetch paths's relative to its owner.
	TargetPaths func() page.TargetPaths

	// Need one of these to load the resource content.
	SourceFile         source.File
	OpenReadSeekCloser resource.OpenReadSeekCloser

	FileInfo os.FileInfo

	// If OpenReadSeekerCloser is not set, we use this to open the file.
	SourceFilename string

	Fs afero.Fs

	// The relative target filename without any language code.
	RelTargetFilename 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

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

func (ResourceSourceDescriptor) Filename

func (r ResourceSourceDescriptor) Filename() string

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 ...interface{}) ResourceTransformation

type ResourceTransformationCtx

type ResourceTransformationCtx struct {
	// 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]interface{}

	// 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

	MediaTypes    media.Types
	OutputFormats output.Formats

	Logger      loggers.Logger
	ErrorSender herrors.ErrorSender

	TextTemplates tpl.TemplateParseFinder

	Permalinks  page.PermalinkExpander
	BuildConfig config.Build

	ResourceCache *ResourceCache
	FileCaches    filecache.Caches

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

func NewSpec

func NewSpec(
	s *helpers.PathSpec,
	fileCaches filecache.Caches,
	incr identity.Incrementer,
	logger loggers.Logger,
	errorHandler herrors.ErrorSender,
	outputFormats output.Formats,
	mimeTypes media.Types) (*Spec, error)

func (*Spec) CacheStats

func (r *Spec) CacheStats() string

func (*Spec) ClearCaches

func (r *Spec) ClearCaches()

func (*Spec) DeleteBySubstring added in v0.65.0

func (r *Spec) DeleteBySubstring(s string)

func (*Spec) New

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 Transformer added in v0.58.0

type Transformer interface {
	Transform(...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.
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 godartsass integrates with the Dass Sass Embedded protocol to transpile SCSS/SASS.
Package godartsass integrates with the Dass 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