diff options
Diffstat (limited to 'content/en/functions/path')
-rw-r--r-- | content/en/functions/path/Base.md | 39 | ||||
-rw-r--r-- | content/en/functions/path/BaseName.md | 37 | ||||
-rw-r--r-- | content/en/functions/path/Clean.md | 42 | ||||
-rw-r--r-- | content/en/functions/path/Dir.md | 41 | ||||
-rw-r--r-- | content/en/functions/path/Ext.md | 33 | ||||
-rw-r--r-- | content/en/functions/path/Join.md | 44 | ||||
-rw-r--r-- | content/en/functions/path/Split.md | 45 | ||||
-rw-r--r-- | content/en/functions/path/_index.md | 12 |
8 files changed, 132 insertions, 161 deletions
diff --git a/content/en/functions/path/Base.md b/content/en/functions/path/Base.md index c00873524..2071f8bea 100644 --- a/content/en/functions/path/Base.md +++ b/content/en/functions/path/Base.md @@ -1,35 +1,26 @@ --- title: path.Base -description: Base returns the last element of a path. -categories: [functions] +description: Replaces path separators with slashes (`/`) and returns the last element of the given path. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/BaseName + - functions/path/Clean + - functions/path/Dir + - functions/path/Ext + - functions/path/Join + - functions/path/Split returnType: string signatures: [path.Base PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.base] --- -`path.Base` returns the last element of `PATH`. - -If `PATH` is empty, `.` is returned. - -**Note:** On Windows, `PATH` is converted to slash (`/`) separators. - ```go-html-template -{{ path.Base "a/news.html" }} → "news.html" -{{ path.Base "news.html" }} → "news.html" -{{ path.Base "a/b/c" }} → "c" -{{ path.Base "/x/y/z/" }} → "z" +{{ path.Base "a/news.html" }} → news.html +{{ path.Base "news.html" }} → news.html +{{ path.Base "a/b/c" }} → c +{{ path.Base "/x/y/z/" }} → z +{{ path.Base "" }} → . ``` diff --git a/content/en/functions/path/BaseName.md b/content/en/functions/path/BaseName.md index a357ed403..4c4340a09 100644 --- a/content/en/functions/path/BaseName.md +++ b/content/en/functions/path/BaseName.md @@ -1,33 +1,28 @@ --- title: path.BaseName -description: BaseName returns the last element of a path, removing the extension if present. -categories: [functions] +description: Replaces path separators with slashes (`/`) and returns the last element of the given path, removing the extension if present. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/Base + - functions/path/Clean + - functions/path/Dir + - functions/path/Ext + - functions/path/Join + - functions/path/Split returnType: string signatures: [path.BaseName PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.basename] --- -If `PATH` is empty, `.` is returned. - -**Note:** On Windows, `PATH` is converted to slash (`/`) separators. +{{< new-in 0.101.0 >}} ```go-html-template -{{ path.BaseName "a/news.html" }} → "news" -{{ path.BaseName "news.html" }} → "news" -{{ path.BaseName "a/b/c" }} → "c" -{{ path.BaseName "/x/y/z/" }} → "z" +{{ path.BaseName "a/news.html" }} → news +{{ path.BaseName "news.html" }} → news +{{ path.BaseName "a/b/c" }} → c +{{ path.BaseName "/x/y/z/" }} → z +{{ path.BaseName "" }} → . ``` diff --git a/content/en/functions/path/Clean.md b/content/en/functions/path/Clean.md index 98160c568..57a665c03 100644 --- a/content/en/functions/path/Clean.md +++ b/content/en/functions/path/Clean.md @@ -1,35 +1,33 @@ --- title: path.Clean -description: Replaces path separators with slashes (`/`) and removes extraneous separators. -categories: [functions] +description: Replaces path separators with slashes (`/`) and returns the shortest path name equivalent to the given path. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/Base + - functions/path/BaseName + - functions/path/Dir + - functions/path/Ext + - functions/path/Join + - functions/path/Split returnType: string signatures: [path.Clean PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.clean] --- -`path.Clean` replaces path separators with slashes (`/`) and removes extraneous separators, including trailing separators. +See Go's [`path.Clean`] documentation for details. -```go-html-template -{{ path.Clean "foo//bar" }} → "foo/bar" -{{ path.Clean "/foo/bar/" }} → "/foo/bar" -``` - -On a Windows system, if `.File.Path` is `foo\bar.md`, then: +[`path.Clean`]: https://pkg.go.dev/path#Clean ```go-html-template -{{ path.Clean .File.Path }} → "foo/bar.md" +{{ path.Clean "foo/bar" }} → foo/bar +{{ path.Clean "/foo/bar" }} → /foo/bar +{{ path.Clean "/foo/bar/" }} → /foo/bar +{{ path.Clean "/foo//bar/" }} → /foo/bar +{{ path.Clean "/foo/./bar/" }} → /foo/bar +{{ path.Clean "/foo/../bar/" }} → /bar +{{ path.Clean "/../foo/../bar/" }} → /bar +{{ path.Clean "" }} → . ``` diff --git a/content/en/functions/path/Dir.md b/content/en/functions/path/Dir.md index 0a2928696..6d5e5c975 100644 --- a/content/en/functions/path/Dir.md +++ b/content/en/functions/path/Dir.md @@ -1,36 +1,27 @@ --- title: path.Dir -description: Dir returns all but the last element of a path. -categories: [functions] +description: Replaces path separators with slashes (/) and returns all but the last element of the given path. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/Base + - functions/path/BaseName + - functions/path/Clean + - functions/path/Ext + - functions/path/Join + - functions/path/Split returnType: string signatures: [path.Dir PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.dir] --- -`path.Dir` returns all but the last element of `PATH`, typically `PATH`'s directory. - -The returned path will never end in a slash. -If `PATH` is empty, `.` is returned. - -**Note:** On Windows, `PATH` is converted to slash (`/`) separators. - ```go-html-template -{{ path.Dir "a/news.html" }} → "a" -{{ path.Dir "news.html" }} → "." -{{ path.Dir "a/b/c" }} → "a/b" -{{ path.Dir "/x/y/z" }} → "/x/y" +{{ path.Dir "a/news.html" }} → a +{{ path.Dir "news.html" }} → . +{{ path.Dir "a/b/c" }} → a/b +{{ path.Dir "/a/b/c" }} → /a/b +{{ path.Dir "/a/b/c/" }} → /a/b/c +{{ path.Dir "" }} → . ``` diff --git a/content/en/functions/path/Ext.md b/content/en/functions/path/Ext.md index 6b5685948..f3e47aecd 100644 --- a/content/en/functions/path/Ext.md +++ b/content/en/functions/path/Ext.md @@ -1,33 +1,24 @@ --- title: path.Ext -description: Ext returns the file name extension of a path. -categories: [functions] +description: Replaces path separators with slashes (`/`) and returns the file name extension of the given path. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/Base + - functions/path/BaseName + - functions/path/Clean + - functions/path/Dir + - functions/path/Join + - functions/path/Split returnType: string signatures: [path.Ext PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.ext] --- -`path.Ext` returns the file name extension `PATH`. - -The extension is the suffix beginning at the final dot in the final slash-separated element `PATH`; -it is empty if there is no dot. - -**Note:** On Windows, `PATH` is converted to slash (`/`) separators. +The extension is the suffix beginning at the final dot in the final slash-separated element of path; it is empty if there is no dot. ```go-html-template -{{ path.Ext "a/b/c/news.html" }} → ".html" +{{ path.Ext "a/b/c/news.html" }} → .html ``` diff --git a/content/en/functions/path/Join.md b/content/en/functions/path/Join.md index 4f5c51c0f..dc701b731 100644 --- a/content/en/functions/path/Join.md +++ b/content/en/functions/path/Join.md @@ -1,34 +1,36 @@ --- title: path.Join -description: Join path elements into a single path. -categories: [functions] +description: Replaces path separators with slashes (`/`), joins the given path elements into a single path, and returns the shortest path name equivalent to the result. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] + related: + - functions/path/Base + - functions/path/BaseName + - functions/path/Clean + - functions/path/Dir + - functions/path/Ext + - functions/path/Split + - functions/urls/JoinPath returnType: string signatures: [path.Join ELEMENT...] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split - - urls.JoinPath aliases: [/functions/path.join] --- -`path.Join` joins path elements into a single path, adding a separating slash if necessary. -All empty strings are ignored. +See Go's [`path.Join`] and [`path.Clean`] documentation for details. + +[`path.Clean`]: https://pkg.go.dev/path#Clean +[`path.Join`]: https://pkg.go.dev/path#Join -**Note:** All path elements on Windows are converted to slash ('/') separators. ```go-html-template -{{ path.Join "partial" "news.html" }} → "partial/news.html" -{{ path.Join "partial/" "news.html" }} → "partial/news.html" -{{ path.Join "foo/baz" "bar" }} → "foo/baz/bar" +{{ path.Join "partial" "news.html" }} → partial/news.html +{{ path.Join "partial/" "news.html" }} → partial/news.html +{{ path.Join "foo/bar" "baz" }} → foo/bar/baz +{{ path.Join "foo" "bar" "baz" }} → foo/bar/baz +{{ path.Join "foo" "" "baz" }} → foo/baz +{{ path.Join "foo" "." "baz" }} → foo/baz +{{ path.Join "foo" ".." "baz" }} → baz +{{ path.Join "/.." "foo" ".." "baz" }} → baz ``` diff --git a/content/en/functions/path/Split.md b/content/en/functions/path/Split.md index bde412743..329d73954 100644 --- a/content/en/functions/path/Split.md +++ b/content/en/functions/path/Split.md @@ -1,43 +1,34 @@ --- title: path.Split -description: Split path immediately following the final slash. -categories: [functions] +description: Replaces path separators with slashes (`/`) and splits the resulting path immediately following the final slash, separating it into a directory and file name component. +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] - returnType: DirFile + related: + - functions/path/Base + - functions/path/BaseName + - functions/path/Clean + - functions/path/Dir + - functions/path/Ext + - functions/path/Join + returnType: paths.DirFile signatures: [path.Split PATH] -relatedFunctions: - - path.Base - - path.BaseName - - path.Clean - - path.Dir - - path.Ext - - path.Join - - path.Split aliases: [/functions/path.split] --- -`path.Split` splits `PATH` immediately following the final slash, separating it into a directory and a base component. - -The returned values have the property that `PATH` = `DIR`+`BASE`. -If there is no slash in `PATH`, it returns an empty directory and the base is set to `PATH`. - -**Note:** On Windows, `PATH` is converted to slash (`/`) separators. +If there is no slash in the given path, `path.Split` returns an empty directory, and file set to path. The returned values have the property that path = dir+file. ```go-html-template {{ $dirFile := path.Split "a/news.html" }} -{{ $dirFile.Dir }} → "a/" -{{ $dirFile.File }} → "news.html" +{{ $dirFile.Dir }} → a/ +{{ $dirFile.File }} → news.html {{ $dirFile := path.Split "news.html" }} -{{ $dirFile.Dir }} → "" -{{ $dirFile.File }} → "news.html" +{{ $dirFile.Dir }} → "" (empty string) +{{ $dirFile.File }} → news.html {{ $dirFile := path.Split "a/b/c" }} -{{ $dirFile.Dir }} → "a/b/" -{{ $dirFile.File }} → "c" +{{ $dirFile.Dir }} → a/b/ +{{ $dirFile.File }} → c ``` diff --git a/content/en/functions/path/_index.md b/content/en/functions/path/_index.md new file mode 100644 index 000000000..2d7ce8e90 --- /dev/null +++ b/content/en/functions/path/_index.md @@ -0,0 +1,12 @@ +--- +title: Path functions +linkTitle: path +description: Template functions to work with file paths. +categories: [] +keywords: [] +menu: + docs: + parent: functions +--- + +Use these functions to work with file paths. |