package create

import "github.com/gohugoio/hugo/resources/resource_factories/create"

Package create contains functions for to create Resource objects. This will typically non-files.

Index

Types

type Client

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

Client contains methods to create Resource objects. tasks to Resource objects.

func New

func New(rs *resources.Spec) *Client

New creates a new Client with the given specification.

func (*Client) ByType

func (c *Client) ByType(tp string) resource.Resources

func (*Client) Copy

func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource, error)

Copy copies r to the new targetPath.

func (*Client) FromOpts

func (c *Client) FromOpts(opts Options) (resource.Resource, error)

FromOpts creates a new Resource from the given Options. Make sure to set optis.TargetPathHasHash if the TargetPath already contains a hash, as this avoids the need to calculate it. To create a new ReadSeekCloser from a string, use hugio.NewReadSeekerNoOpCloserFromString, or hugio.NewReadSeekerNoOpCloserFromBytes for a byte slice. See FromString.

func (*Client) FromRemote

func (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resource, error)

FromRemote expects one or n-parts of a URL to a resource If you provide multiple parts they will be joined together to the final URL.

func (*Client) FromString

func (c *Client) FromString(targetPath, content string) (resource.Resource, error)

FromString creates a new Resource from a string with the given relative target path.

func (*Client) Get

func (c *Client) Get(pathname string) (resource.Resource, error)

Get creates a new Resource by opening the given pathname in the assets filesystem.

func (*Client) GetMatch

func (c *Client) GetMatch(pattern string) (resource.Resource, error)

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

func (*Client) Match

func (c *Client) Match(pattern string) (resource.Resources, error)

Match gets the resources matching the given pattern from the assets filesystem.

type HTTPError

type HTTPError struct {
	Data map[string]any

	StatusCode int
	Body       string
	// contains filtered or unexported fields
}

type Options

type Options struct {
	// The target path relative to the publish directory.
	// Unix style path, i.e. "images/logo.png".
	TargetPath string

	// Whether the TargetPath has a hash in it which will change if the resource changes.
	// If not, we will calculate a hash from the content.
	TargetPathHasHash bool

	// The content to create the Resource from.
	CreateContent func() (func() (hugio.ReadSeekCloser, error), error)
}

Source Files

create.go remote.go

Version
v0.144.2 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
35 packages
Last checked
13 hours ago

Tools for package owners.