resources

package
v0.0.0-...-f0d32e8 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyGetJSON     = "getjson"
	KeyGetCSV      = "getcsv"
	KeyImages      = "images"
	KeyAssets      = "assets"
	KeyModules     = "modules"
	KeyGetResource = "getresource"
)

Variables

View Source
var (
	ImageFormatsBySubType = map[string]ImageFormat{
		media.Builtin.JPEGType.SubType: JPEG,
		media.Builtin.PNGType.SubType:  PNG,
		media.Builtin.TIFFType.SubType: TIFF,
		media.Builtin.BMPType.SubType:  BMP,
		media.Builtin.GIFType.SubType:  GIF,
		media.Builtin.WEBPType.SubType: WEBP,
	}
)

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig interface {
	CachesIterator(func(cacheKey string, isResourceDir bool, dir string, age time.Duration))
}

type Cloner

type Cloner interface {
	Clone() Resource
}

type ContentProvider

type ContentProvider 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(context.Context) (any, error)
}

ContentProvider provides Content. 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 Copier

type Copier interface {
	CloneTo(targetPath string) Resource
}

Copier is for internal use.

type Creator

type Creator interface {
	GetResource(pathname string) (Resource, error)
}

type DataProvider

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

type ErrProvider

type ErrProvider interface {
	// Err returns an error if this resource is in an error state.
	// This will currently only be set for resources obtained from resources.GetRemote.
	Err() ResourceError
}

ErrProvider provides an Err.

type Fs

type Fs interface {
	SourceFs() afero.Fs
	AssetsFs() afero.Fs
	PublishFs() afero.Fs
	ResourcesCacheFs() afero.Fs

	AssetsFsRealFilename(rel string) string
	AssetsFsRealDirs(from string) []string
	AssetsFsMakePathRelative(filename string, checkExists bool) (string, bool)

	NewBasePathFs(source afero.Fs, path string) afero.Fs
	Glob(fs afero.Fs, pattern string, handle func(fi fsVO.FileMetaInfo) (bool, error)) error
}

type Giphy

type Giphy interface {
	image.Image    // The first frame.
	GIF() *gif.GIF // All frames.
}

Giphy represents a GIF Image that may be animated.

type Identifier

type Identifier interface {
	// Key is is mostly for internal use and should be considered opaque.
	// This value may change between Hugo versions.
	Key() string
}

Identifier identifies a resource.

type ImageConfig

type ImageConfig interface {
	ExifDecoder() (*exif.Decoder, error)
	ImageHint() webpoptions.EncodingPreset
	ImageQuality() int
	Resampling() gift.Resampling
	ResamplingStr() string
	Anchor() gift.Anchor
	AnchorStr() string
	BgColor() color.Color
	BgColorStr() string
	SourceHash() string
}

type ImageFormat

type ImageFormat int

ImageFormat is an images file format.

const (
	JPEG ImageFormat = iota + 1
	PNG
	GIF
	TIFF
	BMP
	WEBP
)

type ImageResource

type ImageResource interface {
	Resource
	ImageResourceOps
}

ImageResource represents an images resource.

type ImageResourceOps

type ImageResourceOps interface {
	// Height returns the height of the Image.
	Height() int

	// Width returns the width of the Image.
	Width() int

	// Process applies the given images processing options to the images.
	Process(spec string) (ImageResource, error)

	// Crop an images to match the given dimensions without resizing.
	// You must provide both width and height.
	// Use the anchor option to change the crop box anchor point.
	//    {{ $images := $images.Crop "600x400" }}
	Crop(spec string) (ImageResource, error)

	// Fill scales the images to the smallest possible size that will cover the specified dimensions in spec,
	// crops the resized images to the specified dimensions using the given anchor point.
	// The spec is space delimited, e.g. `200x300 TopLeft`.
	Fill(spec string) (ImageResource, error)

	// Fit scales down the images using the given spec.
	Fit(spec string) (ImageResource, error)

	// Resize resizes the images to the given spec. If one of width or height is 0, the images aspect
	// ratio is preserved.
	Resize(spec string) (ImageResource, error)

	// Filter applies one or more filters to an Image.
	//    {{ $images := $images.Filter (images.GaussianBlur 6) (images.Pixelate 8) }}
	Filter(filters ...any) (ImageResource, error)

	// Exif returns an ExifInfo object containing Image metadata.
	Exif() *exif.ExifInfo

	// Colors returns a slice of the most dominant colors in an images
	// using a simple histogram method.
	Colors() ([]string, error)

	// For internal use.
	DecodeImage() (image.Image, error)
}

type LinksProvider

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

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

type MediaTypeProvider

type MediaTypeProvider interface {
	// MediaType is this resource's MIME type.
	MediaType() media.Type
}

type MediaTypesConfig

type MediaTypesConfig interface {
	LookFirstBySuffix(suffix string) (media.Type, media.SuffixInfo, bool)
	LookByType(mediaType string) (media.Type, bool)
	MediaTypes() media.Types
}

type MetaProvider

type MetaProvider interface {
	NameTitleProvider
	ParamsProvider
}

MetaProvider provides metadata about a resource.

type MinifyConfig

type MinifyConfig interface {
	IsMinifyPublish() bool
	GetMinifier(s string) minify.Minifier
	Minifiers(mediaTypes media.Types, cb func(media.Type, minify.Minifier))
}

type NameNormalizedProvider

type NameNormalizedProvider interface {
	// NameNormalized is the normalized name of this resource.
	// For internal use (for now).
	NameNormalized() string
}

type NameTitleProvider

type NameTitleProvider interface {
	// 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 images "/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
}

type OriginProvider

type OriginProvider interface {
	Origin() Resource
	GetFieldString(pattern string) (string, bool)
}

OriginProvider provides the original Resource if this is wrapped. This is an internal Hugo interface and not meant for use in the templates.

type OutputFormatsConfig

type OutputFormatsConfig interface {
	AllOutputFormats() output.Formats
}

type ParamsProvider

type ParamsProvider interface {
	// Params set in front matter for this resource.
	Params() maps.Params
}

type ReadSeekCloserResource

type ReadSeekCloserResource interface {
	MediaType() media.Type
	pio.ReadSeekCloserProvider
}

ReadSeekCloserResource is a Resource that supports loading its content.

type ResourceCopier

type ResourceCopier interface {
	CloneTo(targetPath string) Resource
}

type ResourceError

type ResourceError interface {
	error
	DataProvider
}

ResourceError is the error return from .Err in Resource in error situations.

type ResourcePaths

type ResourcePaths interface {
	PathDir() string
	PathBaseDirTarget() string
	PathBaseDirLink() string
	PathTargetBasePaths() []string
	PathFile() string
}

type Resources

type Resources interface {
	Creator
}

type SecurityConfig

type SecurityConfig interface {
	ExecAuth() hexec.ExecAuth
}

type SiteUrl

type SiteUrl interface {
	BasePathNoSlash() string
}

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 TypeProvider

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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