valueobject

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionResize = "resize"
	ActionCrop   = "crop"
	ActionFit    = "fit"
	ActionFill   = "fill"
)
View Source
const (
	HugoVarsNamespace = "hugo:vars"
)

Variables

View Source
var DartSassBinaryName string

Functions

func ClassifyType

func ClassifyType(t string) string

func ContentReadSeekerCloser

func ContentReadSeekerCloser(r resources.Resource) (pio.ReadSeekCloser, error)

ContentReadSeekerCloser returns a ReadSeekerCloser if possible for a given Resource.

func CreateVarsStyleSheet

func CreateVarsStyleSheet(vars map[string]any) string

func DefaultExtension

func DefaultExtension(f resources.ImageFormat) string

DefaultExtension returns the default file extension of this format, starting with a dot. For example: .jpg for resources.JPEG

func ImageFormatFromExt

func ImageFormatFromExt(ext string) (resources.ImageFormat, bool)

func ImageFormatFromMediaSubType

func ImageFormatFromMediaSubType(sub string) (resources.ImageFormat, bool)

func IsDartSassV2

func IsDartSassV2() bool

func IsOpaque

func IsOpaque(img image.Image) bool

IsOpaque returns false if the images has alpha channel and there is at least 1 pixel that is not (fully) opaque.

func MediaType

func MediaType(f resources.ImageFormat) media.Type

MediaType returns the media type of this images, e.g. images/jpeg for resources.JPEG

func RequiresDefaultQuality

func RequiresDefaultQuality(f resources.ImageFormat) bool

RequiresDefaultQuality returns if the default quality needs to be applied to images of this format.

func SetDartSassBinaryName

func SetDartSassBinaryName()

func SupportsTransparency

func SupportsTransparency(f resources.ImageFormat) bool

SupportsTransparency reports whether it supports transparency in any form.

func ToFilters

func ToFilters(in any) []gift.Filter

ToFilters converts the given input to a slice of gift.Filter.

func UnwrapFilter

func UnwrapFilter(in gift.Filter) gift.Filter

UnwrapFilter unwraps the given filter if it is a filter wrapper.

Types

type DartSassOptions

type DartSassOptions struct {
	// Hugo, will by default, just replace the extension of the source
	// to .css, e.g. "scss/main.scss" becomes "scss/main.css". You can
	// control this by setting this, e.g. "styles/main.css" will create
	// a Resource with that as a base for RelPermalink etc.
	TargetPath string

	// Hugo automatically adds the entry directories (where the main.scss lives)
	// for project and themes to the list of include paths sent to LibSASS.
	// Any paths set in this setting will be appended. Note that these will be
	// treated as relative to the working dir, i.e. no include paths outside the
	// project/themes.
	IncludePaths []string

	// Default is nested.
	// One of nested, expanded, compact, compressed.
	OutputStyle string

	// When enabled, Hugo will generate a source map.
	EnableSourceMap bool

	// If enabled, sources will be embedded in the generated source map.
	SourceMapIncludeSources bool

	// Vars will be available in 'hugo:vars', e.g:
	//     @use "hugo:vars";
	//     $color: vars.$color;
	Vars map[string]any
}

func DecodeDartSassOptions

func DecodeDartSassOptions(m map[string]any) (opts DartSassOptions, err error)

type FileCaches

type FileCaches map[string]*filecache.Cache

FileCaches is a named set of caches.

func (FileCaches) AssetsCache

func (f FileCaches) AssetsCache() *filecache.Cache

AssetsCache gets the file cache for assets (processed resources, SCSS etc.).

func (FileCaches) Get

func (f FileCaches) Get(name string) *filecache.Cache

Get gets a named cache, nil if none found.

func (FileCaches) GetCSVCache

func (f FileCaches) GetCSVCache() *filecache.Cache

GetCSVCache gets the file cache for getCSV.

func (FileCaches) GetJSONCache

func (f FileCaches) GetJSONCache() *filecache.Cache

GetJSONCache gets the file cache for getJSON.

func (FileCaches) GetResourceCache

func (f FileCaches) GetResourceCache() *filecache.Cache

GetResourceCache gets the file cache for remote resources.

func (FileCaches) ImageCache

func (f FileCaches) ImageCache() *filecache.Cache

type Filter

type Filter struct {
	Options filterOpts
	gift.Filter
}

type Giphy

type Giphy struct {
	image.Image
	Gif *gif.GIF
}

func (*Giphy) GIF

func (g *Giphy) GIF() *gif.GIF

type Image

type Image struct {
	ImageFormat resources.ImageFormat
	Spec        pio.ReadSeekCloserProvider
	// contains filtered or unexported fields
}

func (*Image) EncodeTo

func (i *Image) EncodeTo(conf ImageConfig, img image.Image, w io.Writer) error

func (*Image) Height

func (i *Image) Height() int

Height returns i's height.

func (*Image) InitConfig

func (i *Image) InitConfig(r io.Reader) error

InitConfig reads the images config from the given reader.

func (*Image) Width

func (i *Image) Width() int

Width returns i's width.

func (*Image) WithImage

func (i *Image) WithImage(img image.Image) *Image

func (*Image) WithSpec

func (i *Image) WithSpec(s pio.ReadSeekCloserProvider) *Image

type ImageConfig

type ImageConfig struct {
	// This defines the output format of the output images. It defaults to the source format.
	TargetFormat resources.ImageFormat

	Action string

	// If set, this will be used as the key in filenames etc.
	Key string

	// Quality ranges from 1 to 100 inclusive, higher is better.
	// This is only relevant for JPEG and WEBP images.
	// Default is 75.
	Quality int

	// Rotate rotates an images by the given angle counter-clockwise.
	// The rotation will be performed first.
	Rotate int

	// Used to fill any transparency.
	// When set in site config, it's used when converting to a format that does
	// not support transparency.
	// When set per images operation, it's used even for formats that does support
	// transparency.
	BgColor    color.Color
	BgColorStr string

	// Hint about what type of picture this is. Used to optimize encoding
	// when target is set to webp.
	Hint webpoptions.EncodingPreset

	Width  int
	Height int

	Filter    gift.Resampling
	FilterStr string

	Anchor    gift.Anchor
	AnchorStr string
	// contains filtered or unexported fields
}

ImageConfig holds configuration to create a new images from an existing one, resize etc.

func DecodeImageConfig

func DecodeImageConfig(action string, options []string, defaults resources.ImageConfig, sourceFormat resources.ImageFormat) (ImageConfig, error)

func GetDefaultImageConfig

func GetDefaultImageConfig(action string, defaults resources.ImageConfig) ImageConfig

func (ImageConfig) GetKey

func (i ImageConfig) GetKey(format resources.ImageFormat) string

type ImageFilterFromOrientationProvider

type ImageFilterFromOrientationProvider interface {
	AutoOrient(exifInfo *exif.ExifInfo) gift.Filter
}

type ImageProcessSpecProvider

type ImageProcessSpecProvider interface {
	ImageProcessSpec() string
}

type ImageProcessor

type ImageProcessor struct {
	ExifDecoder *exif.Decoder
}

func (*ImageProcessor) ApplyFiltersFromConfig

func (p *ImageProcessor) ApplyFiltersFromConfig(src image.Image, conf ImageConfig) (image.Image, error)

func (*ImageProcessor) DecodeExif

func (p *ImageProcessor) DecodeExif(r io.Reader) (*exif.ExifInfo, error)

func (*ImageProcessor) Filter

func (p *ImageProcessor) Filter(src image.Image, filters ...gift.Filter) (image.Image, error)

func (*ImageProcessor) FiltersFromConfig

func (p *ImageProcessor) FiltersFromConfig(src image.Image, conf ImageConfig) ([]gift.Filter, error)

type ImageSource

type ImageSource interface {
	DecodeImage() (image.Image, error)
	Key() string
}

ImageSource identifies and decodes an images.

type ImportResolver

type ImportResolver struct {
	BaseDir           string
	FsService         resources.Fs
	DependencyManager identity.Manager
	VarsStylesheet    godartsass.Import
}

func (ImportResolver) CanonicalizeURL

func (t ImportResolver) CanonicalizeURL(url string) (string, error)

func (ImportResolver) Load

func (t ImportResolver) Load(url string) (godartsass.Import, error)

type ImportResolverV1

type ImportResolverV1 struct {
	godartsass.ImportResolver
}

func (ImportResolverV1) Load

type PublishOnce

type PublishOnce struct {
	PublisherInit sync.Once
	PublisherErr  error
}

type ResTransCtxBuilder

type ResTransCtxBuilder struct {
	DepSvc resources.DependenceSvc
	PubSvc resources.PublishSvc
	// contains filtered or unexported fields
}

func (*ResTransCtxBuilder) Build

func (*ResTransCtxBuilder) WithMediaType

func (b *ResTransCtxBuilder) WithMediaType(m media.Type) *ResTransCtxBuilder

func (*ResTransCtxBuilder) WithSource

func (*ResTransCtxBuilder) WithTargetPath

func (b *ResTransCtxBuilder) WithTargetPath(targetPath string) *ResTransCtxBuilder

type ResourceHash

type ResourceHash struct {
	Value    string
	Size     int64
	InitOnce sync.Once
}

func (*ResourceHash) Setup

type ResourceMetadata

type ResourceMetadata struct {
	Target     string         `json:"Target"`
	MediaTypeV string         `json:"MediaType"`
	MetaData   map[string]any `json:"Data"`
}

func (ResourceMetadata) Marshal

func (r ResourceMetadata) Marshal() ([]byte, error)

func (ResourceMetadata) Unmarshal

func (r ResourceMetadata) Unmarshal(data []byte) (ResourceMetadata, error)

type ResourcePaths

type ResourcePaths struct {
	// This is the directory component for the target file or link.
	Dir string

	// Any base directory for the target file. Will be prepended to Dir.
	BaseDirTarget string

	// This is the directory component for the link will be prepended to Dir.
	BaseDirLink string

	// Set when publishing in a multihost setup.
	TargetBasePaths []string

	// This is the File component, e.g. "data.json".
	File string
}

ResourcePaths holds path information for a resource. All directories in here have Unix-style slashes, with leading slash, but no trailing slash. Empty directories are represented with an empty string.

func NewResourcePaths

func NewResourcePaths(targetPath string) ResourcePaths

func (ResourcePaths) FromTargetPath

func (d ResourcePaths) FromTargetPath(targetPath string) ResourcePaths

func (ResourcePaths) Path

func (d ResourcePaths) Path() string
func (d ResourcePaths) PathBaseDirLink() string

func (ResourcePaths) PathBaseDirTarget

func (d ResourcePaths) PathBaseDirTarget() string

func (ResourcePaths) PathDir

func (d ResourcePaths) PathDir() string

func (ResourcePaths) PathFile

func (d ResourcePaths) PathFile() string

func (ResourcePaths) PathTargetBasePaths

func (d ResourcePaths) PathTargetBasePaths() []string

func (ResourcePaths) TargetFilenames

func (d ResourcePaths) TargetFilenames() []string
func (d ResourcePaths) TargetLink() string

func (ResourcePaths) TargetPath

func (d ResourcePaths) TargetPath() string

func (ResourcePaths) TargetPaths

func (d ResourcePaths) TargetPaths() []string

type ResourceTransformationCtx

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

	DepSvc resources.DependenceSvc
	PubSvc resources.PublishSvc

	Source *TransformationSource
	Target *TransformationTarget

	// 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
	// contains filtered or unexported fields
}

func (*ResourceTransformationCtx) AddOutPathIdentifier

func (ctx *ResourceTransformationCtx) AddOutPathIdentifier(identifier string)

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

func (*ResourceTransformationCtx) Close

func (ctx *ResourceTransformationCtx) Close()

func (*ResourceTransformationCtx) ReplaceOutPathExtension

func (ctx *ResourceTransformationCtx) ReplaceOutPathExtension(newExt string)

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

func (*ResourceTransformationCtx) SourcePath

func (ctx *ResourceTransformationCtx) SourcePath() string

func (*ResourceTransformationCtx) UpdateBuffer

func (ctx *ResourceTransformationCtx) UpdateBuffer()

func (*ResourceTransformationCtx) UpdateSource

func (ctx *ResourceTransformationCtx) UpdateSource()

type ResourceTransformationKey

type ResourceTransformationKey struct {
	Name string
	// 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

func NewResourceTransformationKey(name string, elements ...any) 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.

func (ResourceTransformationKey) Value

Value returns the Key as a string. Do not change this without good reasons.

type TransformationSource

type TransformationSource struct {
	// The Content to transform.
	From io.Reader

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

	// The input media type
	InMediaType media.Type
}

type TransformationTarget

type TransformationTarget struct {
	// The target of Content transformation.
	// The current implementation requires that r is written to w
	// even if no transformation is performed.
	To io.Writer

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

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

Jump to

Keyboard shortcuts

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