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 ¶
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 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 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 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 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 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 ¶
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 ¶
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 logcical base name for a resource without any idenifier (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) BundleType ¶
func (*Path) ContainerDir ¶
ContainerDir returns the container directory for this path. For content bundles this will be the parent directory.
func (Path) ForBundleType ¶
func (*Path) Identifier ¶
func (*Path) IdentifierBase ¶
IdentifierBase satifies identity.Identity.
func (*Path) Identifiers ¶
func (*Path) IsBranchBundle ¶
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) IsLeafBundle ¶
func (*Path) NameNoIdentifier ¶
NameNoIdentifier returns the last element of path withhout any identifier (e.g. no extension).
func (*Path) NameNoLang ¶
Name returns the last element of path withhout any language identifier.
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) 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 }
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 )