paths

package
v0.84.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 9 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 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 AddTrailingSlash

func AddTrailingSlash(path string) string

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

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 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 FindCWD

func FindCWD() (string, error)

FindCWD returns the current working directory from where the Hugo executable is run.

func GetDottedRelativePath

func GetDottedRelativePath(inPath string) string

GetDottedRelativePath expects a relative path starting after the content directory. It returns a relative path with dots ("..") navigating up the path structure.

func GetRelativePath

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

GetRelativePath returns the relative path of a given path.

func IsAbsURL

func IsAbsURL(path string) bool

IsAbsURL determines whether the given path points to an absolute URL.

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 PathAndExt

func PathAndExt(in string) (string, string)

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

func PathNoExt

func PathNoExt(in string) string

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

func PathPrep

func PathPrep(ugly bool, in string) string

PathPrep prepares the path using the uglify setting to create paths on either the form /section/name/index.html or /section/name.html.

func PrettifyPath

func PrettifyPath(in string) string

PrettifyPath is the same as PrettifyURLPath but for file paths.

/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 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 SanitizeURL

func SanitizeURL(in string) string

SanitizeURL sanitizes the input URL string.

func SanitizeURLKeepTrailingSlash

func SanitizeURLKeepTrailingSlash(in string) string

SanitizeURLKeepTrailingSlash is the same as SanitizeURL, but will keep any trailing slash.

func ToSlashTrimLeading

func ToSlashTrimLeading(s string) string

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

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

Types

type NamedSlice

type NamedSlice struct {
	Name  string
	Slice []string
}

func (NamedSlice) String

func (n NamedSlice) String() string

Jump to

Keyboard shortcuts

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