package resources
import "github.com/gohugoio/hugo/tpl/resources"
Package resources provides template functions for working with resources.
Index ¶
- type Namespace
- func New(deps *deps.Deps) (*Namespace, error)
- func (ns *Namespace) Babel(args ...any) (resource.Resource, error)
- func (ns *Namespace) ByType(typ any) resource.Resources
- func (ns *Namespace) Concat(targetPathIn any, r any) (resource.Resource, error)
- func (ns *Namespace) Copy(s any, r resource.Resource) (resource.Resource, error)
- func (ns *Namespace) ExecuteAsTemplate(ctx context.Context, args ...any) (resource.Resource, error)
- func (ns *Namespace) Fingerprint(args ...any) (resource.Resource, error)
- func (ns *Namespace) FromString(targetPathIn, contentIn any) (resource.Resource, error)
- func (ns *Namespace) Get(filename any) resource.Resource
- func (ns *Namespace) GetMatch(pattern any) resource.Resource
- func (ns *Namespace) GetRemote(args ...any) (resource.Resource, error)
- func (ns *Namespace) Match(pattern any) resource.Resources
- func (ns *Namespace) Minify(r resources.ResourceTransformer) (resource.Resource, error)
- func (ns *Namespace) PostCSS(args ...any) (resource.Resource, error)
- func (ns *Namespace) PostProcess(r resource.Resource) (postpub.PostPublishedResource, error)
- func (ns *Namespace) ToCSS(args ...any) (resource.Resource, error)
Types ¶
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace provides template functions for the "resources" namespace.
func New ¶
New returns a new instance of the resources-namespaced template functions.
func (*Namespace) Babel ¶
Babel processes the given Resource with Babel. Deprecated: Moved to the js namespace in Hugo 0.128.0.
func (*Namespace) ByType ¶
ByType returns resources of a given resource type (e.g. "image").
func (*Namespace) Concat ¶
Concat concatenates a slice of Resource objects. These resources must (currently) be of the same Media Type.
func (*Namespace) Copy ¶
Copy copies r to the new targetPath in s.
func (*Namespace) ExecuteAsTemplate ¶
ExecuteAsTemplate creates a Resource from a Go template, parsed and executed with the given data, and published to the relative target path.
func (*Namespace) Fingerprint ¶
Fingerprint transforms the given Resource with a MD5 hash of the content in the RelPermalink and Permalink.
func (*Namespace) FromString ¶
FromString creates a Resource from a string published to the relative target path.
func (*Namespace) Get ¶
Get locates the filename given in Hugo's assets filesystem and creates a Resource object that can be used for further transformations.
func (*Namespace) GetMatch ¶
GetMatch finds the first Resource matching the given pattern, or nil if none found.
It looks for files in the assets file system.
See Match for a more complete explanation about the rules used.
func (*Namespace) GetRemote ¶
GetRemote gets the URL (via HTTP(s)) in the first argument in args and creates Resource object that can be used for further transformations.
A second argument may be provided with an option map.
Note: This method does not return any error as a second return value, for any error situations the error can be checked in .Err.
func (*Namespace) Match ¶
Match gets all resources matching the given base path 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 files name with path relative to the file system 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.
It looks for files in the assets file system.
See Match for a more complete explanation about the rules used.
func (*Namespace) Minify ¶
Minify minifies the given Resource using the MediaType to pick the correct minifier.
func (*Namespace) PostCSS ¶
PostCSS processes the given Resource with PostCSS. Deprecated: Moved to the css namespace in Hugo 0.128.0.
func (*Namespace) PostProcess ¶
PostProcess processes r after the build.
func (*Namespace) ToCSS ¶
ToCSS converts the given Resource to CSS. You can optional provide an Options object as second argument. As an option, you can e.g. specify e.g. the target path (string) for the converted CSS resource. Deprecated: Moved to the css namespace in Hugo 0.128.0.
Source Files ¶
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 18 packages
- Last checked
- 7 hours ago –
Tools for package owners.