paths

package
v0.134.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 30

Documentation

Index

Constants

View Source
const (
	FilePathSeparator = string(filepath.Separator)
)

FilePathSeparator as defined by os.Separator.

Variables

This section is empty.

Functions

func AbsPathify added in v0.97.0

func AbsPathify(workingDir, inPath string) string

AbsPathify creates an absolute path if given a working dir and a relative path. If already absolute, the path is just cleaned.

func AddContextRoot

func AddContextRoot(baseURL, relativePath string) string

AddContextRoot adds the context root to an URL if it's not already set. For relative URL entries on sites with a base url with a context root set (i.e. http://example.com/mysite), relative URLs must not include the context root if canonifyURLs is enabled. But if it's disabled, it must be set.

func AddLeadingAndTrailingSlash added in v0.123.0

func AddLeadingAndTrailingSlash(path string) string

AddTrailingAndLeadingSlash adds a leading and trailing Unix styled slash (/) if not already there.

func AddLeadingSlash added in v0.123.0

func AddLeadingSlash(path string) string

AddLeadingSlash adds a leading Unix styled slash (/) if not already there.

func AddTrailingSlash

func AddTrailingSlash(path string) string

AddTrailingSlash adds a trailing Unix styled slash (/) if not already there.

func CommonDirPath added in v0.128.0

func CommonDirPath(path1, path2 string) string

CommonDirPath returns the common directory of the given paths.

func Dir added in v0.123.0

func Dir(s string) string

Dir behaves like path.Dir without the path.Clean step.

The returned path ends in a slash only if it is the root "/".

func Ext

func Ext(in string) string

Ext takes a path and returns the extension, including the delimiter, i.e. ".md".

func ExtNoDelimiter

func ExtNoDelimiter(in string) string

ExtNoDelimiter takes a path and returns the extension, excluding the delimiter, i.e. "md".

func FieldsSlash added in v0.123.0

func FieldsSlash(s string) []string

FieldsSlash cuts s into fields separated with '/'.

func FileAndExt

func FileAndExt(in string) (string, string)

FileAndExt takes a path and returns the file and extension separated, the extension including the delimiter, i.e. ".md".

func FileAndExtNoDelimiter

func FileAndExtNoDelimiter(in string) (string, string)

FileAndExtNoDelimiter takes a path and returns the file and extension separated, the extension excluding the delimiter, e.g "md".

func Filename

func Filename(in string) (name string)

Filename takes a file path, strips out the extension, and returns the name of the file.

func GetRelativePath

func GetRelativePath(path, base string) (final string, err error)

GetRelativePath returns the relative path of a given path.

func HasExt added in v0.123.0

func HasExt(p string) bool

HasExt returns true if the Unix styled path has an extension.

func IsSameFilePath added in v0.128.0

func IsSameFilePath(s1, s2 string) bool

IsSameFilePath checks if s1 and s2 are the same file path.

func MakePermalink(host, plink string) *url.URL

MakePermalink combines base URL with content path to create full URL paths. Example

base:   http://spf13.com/
path:   post/how-i-blog
result: http://spf13.com/post/how-i-blog

func MakeTitle

func MakeTitle(inpath string) string

MakeTitle converts the path given to a suitable title, trimming whitespace and replacing hyphens with whitespace.

func ModifyPathBundleTypeResource added in v0.123.0

func ModifyPathBundleTypeResource(p *Path)

func NormalizePathStringBasic added in v0.123.0

func NormalizePathStringBasic(s string) string

NormalizePathString returns a normalized path string using the very basic Hugo rules.

func PathAndExt

func PathAndExt(in string) (string, string)

PathAndExt is the same as FileAndExt, but it uses the path package.

func PathEscape added in v0.123.0

func PathEscape(pth string) string

PathEscape escapes unicode letters in pth. Use URLEscape to escape full URLs including scheme, query etc. This is slightly faster for the common case. Note, there is a url.PathEscape function, but that also escapes /.

func PrettifyURL

func PrettifyURL(in string) string

PrettifyURL takes a URL string and returns a semantic, clean URL.

func PrettifyURLPath

func PrettifyURLPath(in string) string

PrettifyURLPath takes a URL path to a content and converts it to enable pretty URLs.

/section/name.html       becomes /section/name/index.html
/section/name/           becomes /section/name/index.html
/section/name/index.html becomes /section/name/index.html

func ReplaceExtension

func ReplaceExtension(path string, newExt string) string

ReplaceExtension takes a path and an extension, strips the old extension and returns the path with the new extension.

func Sanitize added in v0.123.0

func Sanitize(s string) string

Sanitize sanitizes string to be used in Hugo's file paths and URLs, allowing only a predefined set of special Unicode characters.

Spaces will be replaced with a single hyphen.

This function is the core function used to normalize paths in Hugo.

Note that this is the first common step for URL/path sanitation, the final URL/path may end up looking differently if the user has stricter rules defined (e.g. removePathAccents=true).

func ToSlashPreserveLeading added in v0.123.0

func ToSlashPreserveLeading(s string) string

ToSlashPreserveLeading converts the path given to a forward slash separated path and preserves the leading slash if present trimming any trailing slash.

func ToSlashTrim added in v0.128.0

func ToSlashTrim(s string) string

ToSlashTrim trims any leading and trailing slashes from the given string and converts it to a forward slash separated path.

func ToSlashTrimLeading

func ToSlashTrimLeading(s string) string

ToSlashTrimLeading is just a filepath.ToSlash with an added / prefix trimmer.

func ToSlashTrimTrailing added in v0.123.0

func ToSlashTrimTrailing(s string) string

ToSlashTrimTrailing is just a filepath.ToSlash with an added / suffix trimmer.

func TrimLeading added in v0.128.0

func TrimLeading(s string) string

TrimLeading trims the leading slash from the given string.

func TrimTrailing added in v0.128.0

func TrimTrailing(s string) string

TrimTrailing trims the trailing slash from the given string.

func URLEscape added in v0.123.0

func URLEscape(uri string) string

URLEscape escapes unicode letters.

func Uglify

func Uglify(in string) string

Uglify does the opposite of PrettifyURLPath().

/section/name/index.html becomes /section/name.html
/section/name/           becomes /section/name.html
/section/name.html       becomes /section/name.html

func UrlToFilename added in v0.99.0

func UrlToFilename(s string) (string, bool)

UrlToFilename converts the URL s to a filename. If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.

Types

type DirFile added in v0.110.0

type DirFile struct {
	Dir  string
	File string
}

DirFile holds the result from path.Split.

func (DirFile) String added in v0.110.0

func (df DirFile) String() string

Used in test.

type Path added in v0.123.0

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

func (*Path) Base added in v0.123.0

func (p *Path) Base() string

For content files, Base returns the path without any identifiers (extension, language code etc.). Any 'index' as the last path element is ignored.

For other files (Resources), any extension is kept.

func (*Path) BaseNameNoIdentifier added in v0.123.0

func (p *Path) BaseNameNoIdentifier() string

BaseNameNoIdentifier returns the logical base name for a resource without any identifier (e.g. no extension). For bundles this will be the containing directory's name, e.g. "blog".

func (*Path) BaseNoLeadingSlash added in v0.123.0

func (p *Path) BaseNoLeadingSlash() string

BaseNoLeadingSlash returns the base path without the leading slash.

func (*Path) BaseRel added in v0.123.0

func (p *Path) BaseRel(owner *Path) string

BaseRel returns the base path relative to the given owner.

func (*Path) BundleType added in v0.123.0

func (p *Path) BundleType() PathType

func (*Path) Component added in v0.123.0

func (p *Path) Component() string

Component returns the component for this path (e.g. "content").

func (*Path) Container added in v0.123.0

func (p *Path) Container() string

Container returns the base name of the container directory for this path.

func (*Path) ContainerDir added in v0.123.0

func (p *Path) ContainerDir() string

ContainerDir returns the container directory for this path. For content bundles this will be the parent directory.

func (*Path) Dir added in v0.123.0

func (p *Path) Dir() (d string)

Dir returns all but the last element of path, typically the path's directory.

func (*Path) Disabled added in v0.123.0

func (p *Path) Disabled() bool

func (*Path) Ext added in v0.123.0

func (p *Path) Ext() string

func (Path) ForBundleType added in v0.123.0

func (p Path) ForBundleType(t PathType) *Path

func (*Path) Identifier added in v0.123.0

func (p *Path) Identifier(i int) string

func (*Path) IdentifierBase added in v0.123.0

func (p *Path) IdentifierBase() string

IdentifierBase satisfies identity.Identity.

func (*Path) Identifiers added in v0.123.0

func (p *Path) Identifiers() []string

func (*Path) IsBranchBundle added in v0.123.0

func (p *Path) IsBranchBundle() bool

func (*Path) IsBundle added in v0.123.0

func (p *Path) IsBundle() bool

func (*Path) IsContent added in v0.123.0

func (p *Path) IsContent() bool

IsContent returns true if the path is a content file (e.g. mypost.md). Note that this will also return true for content files in a bundle.

func (*Path) IsContentData added in v0.126.0

func (p *Path) IsContentData() bool

func (*Path) IsLeafBundle added in v0.123.0

func (p *Path) IsLeafBundle() bool

func (*Path) Lang added in v0.123.0

func (p *Path) Lang() string

func (*Path) Name added in v0.123.0

func (p *Path) Name() string

Name returns the last element of path.

func (*Path) NameNoExt added in v0.123.0

func (p *Path) NameNoExt() string

Name returns the last element of path without any extension.

func (*Path) NameNoIdentifier added in v0.123.0

func (p *Path) NameNoIdentifier() string

NameNoIdentifier returns the last element of path without any identifier (e.g. no extension).

func (*Path) NameNoLang added in v0.123.0

func (p *Path) NameNoLang() string

Name returns the last element of path without any language identifier.

func (*Path) Path added in v0.123.0

func (p *Path) Path() (d string)

Path returns the full path.

func (*Path) PathNoIdentifier added in v0.123.0

func (p *Path) PathNoIdentifier() string

PathNoIdentifier returns the Path but with any identifier (ext, lang) removed.

func (*Path) PathNoLang added in v0.123.0

func (p *Path) PathNoLang() string

PathNoLang returns the Path but with any language identifier removed.

func (*Path) PathRel added in v0.123.0

func (p *Path) PathRel(owner *Path) string

PathRel returns the path relative to the given owner.

func (*Path) Section added in v0.123.0

func (p *Path) Section() string

Section returns the first path element (section).

func (Path) TrimLeadingSlash added in v0.123.0

func (p Path) TrimLeadingSlash() *Path

TrimLeadingSlash returns a copy of the Path with the leading slash removed.

func (*Path) Unnormalized added in v0.123.0

func (p *Path) Unnormalized() *Path

Unnormalized returns the Path with the original case preserved.

type PathParser added in v0.123.0

type PathParser struct {
	// Maps the language code to its index in the languages/sites slice.
	LanguageIndex map[string]int

	// Reports whether the given language is disabled.
	IsLangDisabled func(string) bool

	// Reports whether the given ext is a content file.
	IsContentExt func(string) bool
}

PathParser parses a path into a Path.

func (*PathParser) Parse added in v0.123.0

func (pp *PathParser) Parse(c, s string) *Path

Parse parses component c with path s into Path using Hugo's content path rules.

func (*PathParser) ParseBaseAndBaseNameNoIdentifier added in v0.123.3

func (pp *PathParser) ParseBaseAndBaseNameNoIdentifier(c, s string) (string, string)

ParseBaseAndBaseNameNoIdentifier parses component c with path s into a base and a base name without any identifier.

func (*PathParser) ParseIdentity added in v0.123.0

func (pp *PathParser) ParseIdentity(c, s string) identity.StringIdentity

ParseIdentity parses component c with path s into a StringIdentity.

type PathType added in v0.123.0

type PathType int
const (
	// A generic resource, e.g. a JSON file.
	PathTypeFile PathType = iota

	// All below are content files.
	// A resource of a content type with front matter.
	PathTypeContentResource

	// E.g. /blog/my-post.md
	PathTypeContentSingle

	// Leaf bundles, e.g. /blog/my-post/index.md
	PathTypeLeaf

	// Branch bundles, e.g. /blog/_index.md
	PathTypeBranch

	// Content data file, _content.gotmpl.
	PathTypeContentData
)

func (PathType) String added in v0.123.0

func (i PathType) String() string

Jump to

Keyboard shortcuts

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