Version: v0.47.1 Latest Latest

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

Go to latest
Published: Aug 20, 2018 License: Apache-2.0 Imports: 39 Imported by: 0




View Source
const (
	CACHE_CLEAR_ALL = "clear_all"
	CACHE_OTHER     = "other"
View Source
const DefaultResourceType = "unknown"


This section is empty.


func AssignMetadata added in v0.36.1

func AssignMetadata(metadata []map[string]interface{}, resources ...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

func ResourceKeyPartition added in v0.45.1

func ResourceKeyPartition(filename string) string

ResourceKeyPartition returns a partition name to allow for more fine grained cache flushes. It will return the file extension without the leading ".". If no extension, it will return "other".


type Cloner

type Cloner interface {
	WithNewBase(base string) Resource

Cloner is an internal template and not meant for use in the templates. It may change without notice.

type ContentResource added in v0.45.1

type ContentResource interface {

	// Content returns this resource's content. It will be equivalent to reading the content
	// that RelPermalink points to in the published folder.
	// The return type will be contextual, and should be what you would expect:
	// * Page: template.HTML
	// * JSON: String
	// * Etc.
	Content() (interface{}, error)

ContentResource represents a Resource that provides a way to get to its content. Most Resource types in Hugo implements this interface, including Page. This should be used with care, as it will read the file content into memory, but it should be cached as effectively as possible by the implementation.

type Image

type Image struct {
	// contains filtered or unexported fields

func (Image) Content added in v0.40.1

func (l Image) Content() (interface{}, error)

func (Image) Data added in v0.45.1

func (l Image) Data() interface{}

func (*Image) Fill

func (i *Image) Fill(spec string) (*Image, error)

Fill scales the image to the smallest possible size that will cover the specified dimensions, crops the resized image to the specified dimensions using the given anchor point. Space delimited config: 200x300 TopLeft

func (*Image) Fit

func (i *Image) Fit(spec string) (*Image, error)

Fit scales down the image using the specified resample filter to fit the specified maximum width and height.

func (*Image) Height

func (i *Image) Height() int

func (Image) MediaType added in v0.45.1

func (l Image) MediaType() media.Type

func (Image) Name added in v0.36.1

func (l Image) Name() string

func (Image) Params added in v0.36.1

func (l Image) Params() map[string]interface{}
func (l Image) Permalink() string

func (Image) Publish

func (l Image) Publish() error

func (Image) ReadSeekCloser added in v0.45.1

func (l Image) ReadSeekCloser() (ReadSeekCloser, error)
func (l Image) RelPermalink() string

func (*Image) Resize

func (i *Image) Resize(spec string) (*Image, error)

Resize resizes the image to the specified width and height using the specified resampling filter and returns the transformed image. If one of width or height is 0, the image aspect ratio is preserved.

func (Image) ResourceType

func (l Image) ResourceType() string

func (Image) String added in v0.42.1

func (l Image) String() string

func (Image) Title added in v0.36.1

func (l Image) Title() string

func (*Image) Width

func (i *Image) Width() int

func (*Image) WithNewBase

func (i *Image) WithNewBase(base string) Resource

Implement the Cloner interface.

type Imaging

type Imaging struct {
	// Default image quality setting (1-100). Only used for JPEG images.
	Quality int

	// Resample filter used. See
	ResampleFilter string

	// The anchor used in Fill. Default is "smart", i.e. Smart Crop.
	Anchor string

Imaging contains default image processing configuration. This will be fetched from site (or language) config.

type OpenReadSeekCloser added in v0.45.1

type OpenReadSeekCloser func() (ReadSeekCloser, error)

OpenReadSeekeCloser allows setting some other way (than reading from a filesystem) to open or create a ReadSeekCloser.

type ReadSeekCloser added in v0.45.1

type ReadSeekCloser interface {

ReadSeekCloser is implemented by afero.File. We use this as the common type for content in Resource objects, even for strings.

type ReadSeekCloserResource added in v0.45.1

type ReadSeekCloserResource interface {
	ReadSeekCloser() (ReadSeekCloser, error)

ReadSeekCloserResource is a Resource that supports loading its content.

type ReadSeeker added in v0.45.1

type ReadSeeker interface {

ReadSeeker wraps io.Reader and io.Seeker.

type ReadSeekerNoOpCloser added in v0.45.1

type ReadSeekerNoOpCloser struct {

ReadSeekerNoOpCloser implements ReadSeekCloser by doing nothing in Close.

func NewReadSeekerNoOpCloser added in v0.45.1

func NewReadSeekerNoOpCloser(r ReadSeeker) ReadSeekerNoOpCloser

NewReadSeekerNoOpCloser creates a new ReadSeekerNoOpCloser with the given ReadSeeker.

func NewReadSeekerNoOpCloserFromString added in v0.45.1

func NewReadSeekerNoOpCloserFromString(content string) ReadSeekerNoOpCloser

NewReadSeekerNoOpCloserFromString uses strings.NewReader to create a new ReadSeekerNoOpCloser from the given string.

func (ReadSeekerNoOpCloser) Close added in v0.45.1

func (r ReadSeekerNoOpCloser) Close() error

Close does nothing.

type Resource

type Resource interface {
	// Permalink represents the absolute link to this resource.
	Permalink() string

	// RelPermalink represents the host relative link to this resource.
	RelPermalink() string

	// ResourceType is the resource type. For most file types, this is the main
	// part of the MIME type, e.g. "image", "application", "text" etc.
	// For content pages, this value is "page".
	ResourceType() string

	// MediaType is this resource's MIME type.
	MediaType() media.Type

	// Name is the logical name of this resource. This can be set in the front matter
	// metadata for this resource. If not set, Hugo will assign a value.
	// This will in most cases be the base filename.
	// So, for the image "/some/path/sunset.jpg" this will be "sunset.jpg".
	// The value returned by this method will be used in the GetByPrefix and ByPrefix methods
	// on Resources.
	Name() string

	// Title returns the title if set in front matter. For content pages, this will be the expected value.
	Title() string

	// Resource specific data set by Hugo.
	// One example would be.Data.Digest for fingerprinted resources.
	Data() interface{}

	// Params set in front matter for this resource.
	Params() map[string]interface{}

Resource represents a linkable resource, i.e. a content page, image etc.

type ResourceCache added in v0.45.1

type ResourceCache struct {
	// contains filtered or unexported fields

func (*ResourceCache) Contains added in v0.45.1

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

func (*ResourceCache) DeletePartitions added in v0.45.1

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

func (*ResourceCache) GetOrCreate added in v0.45.1

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

type ResourceSourceDescriptor added in v0.45.1

type ResourceSourceDescriptor struct {
	// TargetPathBuilder is a callback to create target paths's relative to its owner.
	TargetPathBuilder func(base string) string

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

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

	// The relative target filename without any language code.
	RelTargetFilename string

	// Any base path prepeneded to the permalink.
	// Typically the language code if this resource should be published to its sub-folder.
	URLBase 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 added in v0.45.1

func (r ResourceSourceDescriptor) Filename() string

type ResourceTransformation added in v0.45.1

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

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

type ResourceTransformationCtx added in v0.45.1

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 publis additional artifacts, e.g. source maps.
	// We may improve this.
	OpenResourcePublisher func(relTargetPath string) (io.WriteCloser, error)

func (*ResourceTransformationCtx) AddOutPathIdentifier added in v0.45.1

func (ctx *ResourceTransformationCtx) AddOutPathIdentifier(identifier string)

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

func (*ResourceTransformationCtx) PublishSourceMap added in v0.45.1

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

func (ctx *ResourceTransformationCtx) ReplaceOutPathExtension(newExt string)

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

type ResourceTransformationKey added in v0.45.1

type ResourceTransformationKey struct {
	// contains filtered or unexported fields

ResourceTransformationKey are provided by the different transformation implementations. It identifies the transformation (name) and its configuration (elements). We combine this in a chain with the rest of the transformations with the target filename and a content hash of the origin to use as cache key.

func NewResourceTransformationKey added in v0.45.1

func NewResourceTransformationKey(name string, elements ...interface{}) ResourceTransformationKey

NewResourceTransformationKey creates a new ResourceTransformationKey from the transformation name and elements. We will create a 64 bit FNV hash from the elements, which when combined with the other key elements should be unique for all practical applications.

type Resources

type Resources []Resource

Resources represents a slice of resources, which can be a mix of different types. I.e. both pages and images etc.

func (Resources) ByType

func (r Resources) ByType(tp string) Resources

func (Resources) GetMatch added in v0.36.1

func (r Resources) GetMatch(pattern string) Resource

GetMatch finds the first Resource matching the given pattern, or nil if none found. See Match for a more complete explanation about the rules used.

func (Resources) Match added in v0.36.1

func (r Resources) Match(pattern string) Resources

Match gets all resources matching the given base filename prefix, e.g "*.png" will match all png files. The "*" does not match path delimiters (/), so if you organize your resources in sub-folders, you need to be explicit about it, e.g.: "images/*.png". To match any PNG image anywhere in the bundle you can do "**.png", and to match all PNG images below the images folder, use "images/**.jpg". The matching is case insensitive. Match matches by using the value of Resource.Name, which, by default, is a filename with path relative to the bundle root with Unix style slashes (/) and no leading slash, e.g. "images/logo.png". See for the full rules set.

func (Resources) MergeByLanguage added in v0.40.1

func (r1 Resources) MergeByLanguage(r2 Resources) Resources

MergeByLanguage adds missing translations in r1 from r2.

func (Resources) MergeByLanguageInterface added in v0.40.1

func (r1 Resources) MergeByLanguageInterface(in interface{}) (interface{}, error)

MergeByLanguageInterface is the generic version of MergeByLanguage. It is here just so it can be called from the tpl package.

type ResourcesLanguageMerger added in v0.40.1

type ResourcesLanguageMerger interface {
	MergeByLanguage(other Resources) Resources
	// Needed for integration with the tpl package.
	MergeByLanguageInterface(other interface{}) (interface{}, error)

type Source

type Source interface {
	Publish() error

Source is an internal template and not meant for use in the templates. It may change without notice.

type Spec

type Spec struct {

	MediaTypes    media.Types
	OutputFormats output.Formats

	Logger *jww.Notepad

	TextTemplates tpl.TemplateParseFinder

	ResourceCache *ResourceCache

	GenImagePath  string
	GenAssetsPath string
	// contains filtered or unexported fields

func NewSpec

func NewSpec(s *helpers.PathSpec, logger *jww.Notepad, outputFormats output.Formats, mimeTypes media.Types) (*Spec, error)

func (*Spec) CacheStats

func (r *Spec) CacheStats() string

func (*Spec) ClearCaches added in v0.45.1

func (r *Spec) ClearCaches()

func (*Spec) DeleteCacheByPrefix

func (r *Spec) DeleteCacheByPrefix(prefix string)

func (*Spec) IsInImageCache added in v0.45.1

func (r *Spec) IsInImageCache(key string) bool

TODO(bep) unify

func (*Spec) New added in v0.45.1

func (*Spec) NewForFs added in v0.45.1

func (r *Spec) NewForFs(sourceFs afero.Fs, fd ResourceSourceDescriptor) (Resource, error)

func (*Spec) Transform added in v0.45.1

func (s *Spec) Transform(r Resource, t ResourceTransformation) (Resource, error)


Path Synopsis
Package bundler contains functions for concatenation etc.
Package bundler contains functions for concatenation etc.
Package create contains functions for to create Resource objects.
Package create contains functions for to create Resource objects.
Package templates contains functions for template processing of Resource objects.
Package templates contains functions for template processing of Resource objects.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL