resource

package
v0.42.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResourceType = "unknown"

Variables

This section is empty.

Functions

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 https://golang.org/pkg/path/#Match

Types

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 Image

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

func (Image) AbsSourceFilename

func (l Image) AbsSourceFilename() string

func (Image) Content added in v0.40.1

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

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) 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 (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 https://github.com/disintegration/imaging
	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 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

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

	// Params set in front matter for this resource.
	Params() map[string]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)
}

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

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) ByPrefix added in v0.36.1

func (r Resources) ByPrefix(prefix string) Resources

ByPrefix gets all resources matching the given base filename prefix, e.g "logo" will match logo.png.

func (Resources) ByType

func (r Resources) ByType(tp string) Resources

func (Resources) GetByPrefix

func (r Resources) GetByPrefix(prefix string) Resource

GetByPrefix gets the first resource matching the given filename prefix, e.g "logo" will match logo.png. It returns nil of none found. In potential ambiguous situations, combine it with ByType.

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 https://github.com/gobwas/glob 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 {
	AbsSourceFilename() string
	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 {
	*helpers.PathSpec

	GenImagePath string
	// contains filtered or unexported fields
}

func NewSpec

func NewSpec(s *helpers.PathSpec, mimeTypes media.Types) (*Spec, error)

func (*Spec) CacheStats

func (r *Spec) CacheStats() string

func (*Spec) DeleteCacheByPrefix

func (r *Spec) DeleteCacheByPrefix(prefix string)

func (*Spec) IsInCache

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

func (*Spec) NewResourceFromFile

func (r *Spec) NewResourceFromFile(
	targetPathBuilder func(base string) string,
	file source.File, relTargetFilename string) (Resource, error)

func (*Spec) NewResourceFromFilename

func (r *Spec) NewResourceFromFilename(
	targetPathBuilder func(base string) string,
	absSourceFilename, relTargetFilename string) (Resource, error)

Jump to

Keyboard shortcuts

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