package path

import "github.com/gohugoio/hugo/tpl/path"

Package path provides template functions for manipulating paths.

Index

Package Files

init.go path.go

type DirFile

type DirFile struct {
    Dir  string
    File string
}

DirFile holds the result from path.Split.

func (DirFile) String

func (df DirFile) String() string

Used in test.

type Namespace

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

Namespace provides template functions for the "os" namespace.

func New

func New(deps *deps.Deps) *Namespace

New returns a new instance of the path-namespaced template functions.

func (*Namespace) Base

func (ns *Namespace) Base(path any) (string, error)

Base returns the last element of path. Trailing slashes are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of slashes, Base returns "/". The input path is passed into filepath.ToSlash converting any Windows slashes to forward slashes.

func (*Namespace) BaseName

func (ns *Namespace) BaseName(path any) (string, error)

BaseName returns the last element of path, removing the extension if present. Trailing slashes are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of slashes, Base returns "/". The input path is passed into filepath.ToSlash converting any Windows slashes to forward slashes.

func (*Namespace) Clean

func (ns *Namespace) Clean(path any) (string, error)

Clean replaces the separators used with standard slashes and then extraneous slashes are removed.

func (*Namespace) Dir

func (ns *Namespace) Dir(path any) (string, error)

Dir returns all but the last element of path, typically the path's directory. After dropping the final element using Split, the path is Cleaned and trailing slashes are removed. If the path is empty, Dir returns ".". If the path consists entirely of slashes followed by non-slash bytes, Dir returns a single slash. In any other case, the returned path does not end in a slash. The input path is passed into filepath.ToSlash converting any Windows slashes to forward slashes.

func (*Namespace) Ext

func (ns *Namespace) Ext(path any) (string, error)

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot. The input path is passed into filepath.ToSlash converting any Windows slashes to forward slashes.

func (*Namespace) Join

func (ns *Namespace) Join(elements ...any) (string, error)

Join joins any number of path elements into a single path, adding a separating slash if necessary. All the input path elements are passed into filepath.ToSlash converting any Windows slashes to forward slashes. The result is Cleaned; in particular, all empty strings are ignored.

func (*Namespace) Split

func (ns *Namespace) Split(path any) (DirFile, error)

Split splits path immediately following the final slash, separating it into a directory and file name component. If there is no slash in path, Split returns an empty dir and file set to path. The input path is passed into filepath.ToSlash converting any Windows slashes to forward slashes. The returned values have the property that path = dir+file.

Version
v0.101.0 (latest)
Published
Jun 16, 2022
Platform
linux/amd64
Imports
7 packages (graph)
Last checked
4 hours ago

Tools for package owners.