paths

package
v0.117.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 7 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 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 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 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 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 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 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