Documentation ¶
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 CommonDir(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 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 ToSlashTrimLeading(s string) string
- func ToSlashTrimTrailing(s string) string
- func URLEscape(uri string) string
- func Uglify(in string) string
- func UrlToFilename(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) IsHTML() 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
- type PathType
Constants ¶
const (
FilePathSeparator = string(filepath.Separator)
)
FilePathSeparator as defined by os.Separator.
Variables ¶
This section is empty.
Functions ¶
func AbsPathify ¶ added in v0.97.0
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 ¶ added in v0.123.0
AddTrailingAndLeadingSlash adds a leading and trailing Unix styled slash (/) if not already there.
func AddLeadingSlash ¶ added in v0.123.0
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 Dir ¶ added in v0.123.0
Dir behaves like path.Dir without the path.Clean step.
The returned path ends in a slash only if it is the root "/".
func ExtNoDelimiter ¶
ExtNoDelimiter takes a path and returns the extension, excluding the delimiter, i.e. "md".
func FieldsSlash ¶ added in v0.123.0
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 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 ¶ added in v0.123.0
func ModifyPathBundleTypeResource(p *Path)
func NormalizePathStringBasic ¶ added in v0.123.0
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 ¶ added in v0.123.0
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 ¶ added in v0.123.0
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
ToSlashPreserveLeading converts the path given to a forward slash separated path and preserves the leading slash if present trimming any trailing slash.
func ToSlashTrimLeading ¶
ToSlashTrimLeading is just a filepath.ToSlash with an added / prefix trimmer.
func ToSlashTrimTrailing ¶ added in v0.123.0
ToSlashTrimTrailing is just a filepath.ToSlash with an added / suffix trimmer.
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 UrlToFilename ¶ added in v0.99.0
UrlToFilename converts the URL s to a filename. If ParseRequestURI fails, the input is just converted to OS specific slashes and returned.
Types ¶
type Path ¶ added in v0.123.0
type Path struct {
// contains filtered or unexported fields
}
func Parse ¶ added in v0.123.0
Parse parses component c with path s into Path using the default path parser.
func (*Path) Base ¶ added in v0.123.0
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
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
BaseNoLeadingSlash returns the base path without the leading slash.
func (*Path) BundleType ¶ added in v0.123.0
func (*Path) Component ¶ added in v0.123.0
Component returns the component for this path (e.g. "content").
func (*Path) Container ¶ added in v0.123.0
Container returns the base name of the container directory for this path.
func (*Path) ContainerDir ¶ added in v0.123.0
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
Dir returns all but the last element of path, typically the path's directory.
func (Path) ForBundleType ¶ added in v0.123.0
func (*Path) Identifier ¶ added in v0.123.0
func (*Path) IdentifierBase ¶ added in v0.123.0
IdentifierBase satisfies identity.Identity.
func (*Path) Identifiers ¶ added in v0.123.0
func (*Path) IsBranchBundle ¶ added in v0.123.0
func (*Path) IsContent ¶ added in v0.123.0
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) IsLeafBundle ¶ added in v0.123.0
func (*Path) NameNoExt ¶ added in v0.123.0
Name returns the last element of path without any extension.
func (*Path) NameNoIdentifier ¶ added in v0.123.0
NameNoIdentifier returns the last element of path without any identifier (e.g. no extension).
func (*Path) NameNoLang ¶ added in v0.123.0
Name returns the last element of path without any language identifier.
func (*Path) PathNoIdentifier ¶ added in v0.123.0
PathNoIdentifier returns the Path but with any identifier (ext, lang) removed.
func (*Path) PathNoLang ¶ added in v0.123.0
PathNoLang returns the Path but with any language identifier removed.
func (Path) TrimLeadingSlash ¶ added in v0.123.0
TrimLeadingSlash returns a copy of the Path with the leading slash removed.
func (*Path) Unnormalized ¶ added in v0.123.0
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 }
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 )