entity

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: 53 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	filecache.Caches

	sync.RWMutex

	CacheImage                  *dynacache.Partition[string, *ResourceImage]
	CacheResource               *dynacache.Partition[string, resources.Resource]
	CacheResources              *dynacache.Partition[string, []resources.Resource]
	CacheResourceTransformation *dynacache.Partition[string, *Resource]
}

func (*Cache) CleanKey

func (c *Cache) CleanKey(key string) string

func (*Cache) GetOrCreateImageResource

func (c *Cache) GetOrCreateImageResource(parent *ResourceImage, conf valueobject.ImageConfig,
	createImage func() (*ResourceImage, image.Image, error)) (*ResourceImage, error)

func (*Cache) GetOrCreateResource

func (c *Cache) GetOrCreateResource(key string, f func() (resources.Resource, error)) (resources.Resource, error)

func (*Cache) GetOrCreateResources

func (c *Cache) GetOrCreateResources(key string, f func() ([]resources.Resource, error)) ([]resources.Resource, error)

func (*Cache) WriteMeta

WriteMeta writes the metadata to file and returns a writer for the content part.

type Common

type Common struct {
	Incr identity.Incrementer

	// Assets used after the build is done.
	// This is shared between all sites.
	*PostBuildAssets
}

type IntegrityClient

type IntegrityClient struct{}

func (*IntegrityClient) Fingerprint

func (c *IntegrityClient) Fingerprint(res resources.Resource, algo string) (resources.Resource, error)

Fingerprint applies fingerprinting of the given resource and hash algorithm. It defaults to sha256 if none given, and the options are md5, sha256 or sha512. The same algo is used for both the fingerprinting part (aka cache busting) and the base64-encoded Subresource Integrity hash, so you will have to stay away from md5 if you plan to use both. See https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity

type MinifierClient

type MinifierClient struct {
	M *minify.M

	// Whether output minification is enabled (HTML in /public)
	MinifyOutput bool
}

MinifierClient for minification of Resource objects. Supported minifiers are: css, html, js, json, svg and xml.

func (*MinifierClient) Minify

func (*MinifierClient) Transformer

func (c *MinifierClient) Transformer(mediatype media.Type) transform.Transformer

type PostBuildAssets

type PostBuildAssets struct {
	PostProcessResources map[string]resources.PostPublishedResource
	JSConfigBuilder      *jsconfig.Builder
	// contains filtered or unexported fields
}

type Resource

type Resource struct {
	stale.Staler
	// contains filtered or unexported fields
}

func (*Resource) CloneTo

func (l *Resource) CloneTo(targetPath string) resources.Resource

func (*Resource) Data

func (l *Resource) Data() any

func (*Resource) Err

func (l *Resource) Err() resources.ResourceError

func (*Resource) Hash

func (l *Resource) Hash() string

func (*Resource) Key

func (l *Resource) Key() string

func (*Resource) MediaType

func (l *Resource) MediaType() media.Type

func (*Resource) Name

func (l *Resource) Name() string

func (*Resource) Params

func (l *Resource) Params() maps.Params
func (l *Resource) Permalink() string

func (*Resource) ReadSeekCloser

func (l *Resource) ReadSeekCloser() (pio.ReadSeekCloser, error)
func (l *Resource) RelPermalink() string

func (*Resource) ResourceType

func (l *Resource) ResourceType() string

func (*Resource) Size

func (l *Resource) Size() int64

func (*Resource) Title

func (l *Resource) Title() string

type ResourceImage

type ResourceImage struct {
	Resource
	*valueobject.Image

	ImageCache  *Cache
	ImageConfig resources.ImageConfig // Image config
	ImageProc   *valueobject.ImageProcessor
	// contains filtered or unexported fields
}

func (*ResourceImage) Colors

func (i *ResourceImage) Colors() ([]string, error)

Colors returns a slice of the most dominant colors in an images using a simple histogram method.

func (*ResourceImage) Crop

Crop the images to the specified dimensions without resizing using the given anchor point. Space delimited config, e.g. `200x300 TopLeft`.

func (*ResourceImage) DecodeImage

func (i *ResourceImage) DecodeImage() (image.Image, error)

DecodeImage decodes the images source into an Image. This for internal use only.

func (*ResourceImage) Exif

func (i *ResourceImage) Exif() *exif.ExifInfo

func (*ResourceImage) Fill

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

func (*ResourceImage) Filter

func (i *ResourceImage) Filter(filters ...any) (resources.ImageResource, error)

func (*ResourceImage) Fit

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

func (*ResourceImage) Process

func (i *ResourceImage) Process(spec string) (resources.ImageResource, error)

Process processes the images with the given spec. The spec can contain an optional action, one of "resize", "crop", "fit" or "fill". This makes this method a more flexible version that covers all of Resize, Crop, Fit and Fill, but it also supports e.g. format conversions without any resize action.

func (*ResourceImage) Resize

func (i *ResourceImage) Resize(spec string) (resources.ImageResource, error)

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

type ResourceTransformable

type ResourceTransformable interface {
	resources.Resource
	Transformer
}

type ResourceTransformation

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

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

type ResourceTransformer

type ResourceTransformer struct {
	Resource

	TransformationCache *Cache
	// contains filtered or unexported fields
}

func (*ResourceTransformer) Transform

func (*ResourceTransformer) TransformWithContext

func (*ResourceTransformer) TransformationKey

func (r *ResourceTransformer) TransformationKey() string

type Resources

type Resources struct {
	*Cache

	ExecHelper *hexec.Exec

	*Common

	FsService    resources.Fs
	MediaService resources.MediaTypesConfig
	UrlService   resources.SiteUrl

	ImageService resources.ImageConfig
	ImageProc    *valueobject.ImageProcessor

	*MinifierClient
	*TemplateClient
	*IntegrityClient
	*SassClient
}

func (*Resources) Copy

func (rs *Resources) Copy(r resources.Resource, targetPath string) (resources.Resource, error)

Copy copies r to the new targetPath.

func (*Resources) GetMatch

func (rs *Resources) GetMatch(pattern string) (resources.Resource, error)

GetMatch gets first resource matching the given pattern from the assets filesystem.

func (*Resources) GetResource

func (rs *Resources) GetResource(pathname string) (resources.Resource, error)

func (*Resources) SetupTemplateClient

func (rs *Resources) SetupTemplateClient(tmpl Template)

type SassClient

type SassClient struct {
	BinaryFound bool
	AllowedExec bool

	FsService resources.Fs
	// contains filtered or unexported fields
}

func (*SassClient) Close

func (c *SassClient) Close() error

func (*SassClient) Open

func (c *SassClient) Open() error

func (*SassClient) ToCSS

func (c *SassClient) ToCSS(res resources.Resource, args map[string]any) (resources.Resource, error)

type Template

type Template interface {
	Parse(name, tpl string) (template.Preparer, error)
	ExecuteWithContext(ctx context.Context, templ template.Preparer, wr io.Writer, data any) error
}

type TemplateClient

type TemplateClient struct {
	T Template
}

func (*TemplateClient) ExecuteAsTemplate

func (c *TemplateClient) ExecuteAsTemplate(ctx context.Context, res resources.Resource, targetPath string, data any) (resources.Resource, error)

type Transformer

type Transformer interface {
	Transform(...ResourceTransformation) (ResourceTransformable, error)
	TransformWithContext(context.Context, ...ResourceTransformation) (ResourceTransformable, error)
}

Jump to

Keyboard shortcuts

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