package paths
import "github.com/gohugoio/hugo/common/paths"
Index ¶
- Constants
- func AbsPathify(workingDir, inPath string) string
- func AddContextRoot(baseURL, relativePath string) string
- func AddLeadingAndTrailingSlash(path string) string
- func AddLeadingSlash(path string) string
- func AddTrailingSlash(path string) string
- func CommonDirPath(path1, path2 string) string
- func Dir(s string) string
- func Ext(in string) string
- func ExtNoDelimiter(in string) string
- func FieldsSlash(s string) []string
- func FileAndExt(in string) (string, string)
- func FileAndExtNoDelimiter(in string) (string, string)
- func Filename(in string) (name string)
- func GetRelativePath(path, base string) (final string, err error)
- func HasExt(p string) bool
- func IsSameFilePath(s1, s2 string) bool
- func MakePermalink(host, plink string) *url.URL
- func MakeTitle(inpath string) string
- func ModifyPathBundleTypeResource(p *Path)
- func NormalizePathStringBasic(s string) string
- func PathAndExt(in string) (string, string)
- func PathEscape(pth string) string
- func PrettifyURL(in string) string
- func PrettifyURLPath(in string) string
- func ReplaceExtension(path string, newExt string) string
- func Sanitize(s string) string
- func ToSlashPreserveLeading(s string) string
- func ToSlashTrim(s string) string
- func ToSlashTrimLeading(s string) string
- func ToSlashTrimTrailing(s string) string
- func TrimExt(in string) string
- func TrimLeading(s string) string
- func TrimTrailing(s string) string
- func URLEscape(uri string) string
- func Uglify(in string) string
- func UrlFromFilename(filename string) (*url.URL, error)
- func UrlStringToFilename(s string) (string, bool)
- type DirFile
- type Path
- func (p *Path) Base() string
- func (p *Path) BaseNameNoIdentifier() string
- func (p *Path) BaseNoLeadingSlash() string
- func (p *Path) BaseRel(owner *Path) string
- func (p *Path) BundleType() PathType
- func (p *Path) Component() string
- func (p *Path) Container() string
- func (p *Path) ContainerDir() string
- func (p *Path) Dir() (d string)
- func (p *Path) Disabled() bool
- func (p *Path) Ext() string
- func (p Path) ForBundleType(t PathType) *Path
- func (p *Path) Identifier(i int) string
- func (p *Path) IdentifierBase() string
- func (p *Path) Identifiers() []string
- func (p *Path) IsBranchBundle() bool
- func (p *Path) IsBundle() bool
- func (p *Path) IsContent() bool
- func (p *Path) IsContentData() bool
- func (p *Path) IsLeafBundle() bool
- func (p *Path) Lang() string
- func (p *Path) Name() string
- func (p *Path) NameNoExt() string
- func (p *Path) NameNoIdentifier() string
- func (p *Path) NameNoLang() string
- func (p *Path) Path() (d string)
- func (p *Path) PathNoIdentifier() string
- func (p *Path) PathNoLang() string
- func (p *Path) PathRel(owner *Path) string
- func (p *Path) Section() string
- func (p Path) TrimLeadingSlash() *Path
- func (p *Path) Unnormalized() *Path
- type PathParser
- func (pp *PathParser) Parse(c, s string) *Path
- func (pp *PathParser) ParseBaseAndBaseNameNoIdentifier(c, s string) (string, string)
- func (pp *PathParser) ParseIdentity(c, s string) identity.StringIdentity
- type PathType
Constants ¶
FilePathSeparator as defined by os.Separator.
Functions ¶
func AbsPathify ¶
AbsPathify creates an absolute path if given a working dir and a relative path. If already absolute, the path is just cleaned.
func AddContextRoot ¶
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 ¶
AddTrailingAndLeadingSlash adds a leading and trailing Unix styled slash (/) if not already there.
func AddLeadingSlash ¶
AddLeadingSlash adds a leading Unix styled slash (/) if not already there.
func AddTrailingSlash ¶
AddTrailingSlash adds a trailing Unix styled slash (/) if not already there.
func CommonDirPath ¶
CommonDirPath returns the common directory of the given paths.
func Dir ¶
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 ¶
Ext takes a path and returns the extension, including the delimiter, i.e. ".md".
func ExtNoDelimiter ¶
ExtNoDelimiter takes a path and returns the extension, excluding the delimiter, i.e. "md".
func FieldsSlash ¶
FieldsSlash cuts s into fields separated with '/'.
func FileAndExt ¶
FileAndExt takes a path and returns the file and extension separated, the extension including the delimiter, i.e. ".md".
func FileAndExtNoDelimiter ¶
FileAndExtNoDelimiter takes a path and returns the file and extension separated, the extension excluding the delimiter, e.g "md".
func Filename ¶
Filename takes a file path, strips out the extension, and returns the name of the file.
func GetRelativePath ¶
GetRelativePath returns the relative path of a given path.
func HasExt ¶
HasExt returns true if the Unix styled path has an extension.
func IsSameFilePath ¶
IsSameFilePath checks if s1 and s2 are the same file path.
func MakePermalink ¶
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 ¶
MakeTitle converts the path given to a suitable title, trimming whitespace and replacing hyphens with whitespace.
func ModifyPathBundleTypeResource ¶
func ModifyPathBundleTypeResource(p *Path)
func NormalizePathStringBasic ¶
NormalizePathString returns a normalized path string using the very basic Hugo rules.
func PathAndExt ¶
PathAndExt is the same as FileAndExt, but it uses the path package.
func PathEscape ¶
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 ¶
PrettifyURL takes a URL string and returns a semantic, clean URL.
func PrettifyURLPath ¶
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 ¶
ReplaceExtension takes a path and an extension, strips the old extension and returns the path with the new extension.
func Sanitize ¶
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 ¶
ToSlashPreserveLeading converts the path given to a forward slash separated path and preserves the leading slash if present trimming any trailing slash.
func ToSlashTrim ¶
ToSlashTrim trims any leading and trailing slashes from the given string and converts it to a forward slash separated path.
func ToSlashTrimLeading ¶
ToSlashTrimLeading is just a filepath.ToSlash with an added / prefix trimmer.
func ToSlashTrimTrailing ¶
ToSlashTrimTrailing is just a filepath.ToSlash with an added / suffix trimmer.
func TrimExt ¶
TrimExt trims the extension from a path..
func TrimLeading ¶
TrimLeading trims the leading slash from the given string.
func TrimTrailing ¶
TrimTrailing trims the trailing slash from the given string.
func URLEscape ¶
URLEscape escapes unicode letters.
func Uglify ¶
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 UrlFromFilename ¶
func UrlStringToFilename ¶
UrlStringToFilename converts the URL s to a filename. If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.
Types ¶
type DirFile ¶
DirFile holds the result from path.Split.
func (DirFile) String ¶
Used in test.
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
func (*Path) Base ¶
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 ¶
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 ¶
BaseNoLeadingSlash returns the base path without the leading slash.
func (*Path) BaseRel ¶
BaseRel returns the base path relative to the given owner.
func (*Path) BundleType ¶
func (*Path) Component ¶
Component returns the component for this path (e.g. "content").
func (*Path) Container ¶
Container returns the base name of the container directory for this path.
func (*Path) ContainerDir ¶
ContainerDir returns the container directory for this path. For content bundles this will be the parent directory.
func (*Path) Dir ¶
Dir returns all but the last element of path, typically the path's directory.
func (*Path) Disabled ¶
func (*Path) Ext ¶
func (Path) ForBundleType ¶
func (*Path) Identifier ¶
func (*Path) IdentifierBase ¶
IdentifierBase satisfies identity.Identity.
func (*Path) Identifiers ¶
func (*Path) IsBranchBundle ¶
func (*Path) IsBundle ¶
func (*Path) IsContent ¶
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 ¶
func (*Path) IsLeafBundle ¶
func (*Path) Lang ¶
func (*Path) Name ¶
Name returns the last element of path.
func (*Path) NameNoExt ¶
Name returns the last element of path without any extension.
func (*Path) NameNoIdentifier ¶
NameNoIdentifier returns the last element of path without any identifier (e.g. no extension).
func (*Path) NameNoLang ¶
Name returns the last element of path without any language identifier.
func (*Path) Path ¶
Path returns the full path.
func (*Path) PathNoIdentifier ¶
PathNoIdentifier returns the Path but with any identifier (ext, lang) removed.
func (*Path) PathNoLang ¶
PathNoLang returns the Path but with any language identifier removed.
func (*Path) PathRel ¶
PathRel returns the path relative to the given owner.
func (*Path) Section ¶
Section returns the first path element (section).
func (Path) TrimLeadingSlash ¶
TrimLeadingSlash returns a copy of the Path with the leading slash removed.
func (*Path) Unnormalized ¶
Unnormalized returns the Path with the original case preserved.
type PathParser ¶
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 ¶
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 ¶
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 ¶
func (pp *PathParser) ParseIdentity(c, s string) identity.StringIdentity
ParseIdentity parses component c with path s into a StringIdentity.
type PathType ¶
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 ¶
Source Files ¶
path.go pathparser.go pathtype_string.go url.go
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 13 packages
- Last checked
- 13 hours ago –
Tools for package owners.