mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 07:00:31 +03:00
Merge commit '35dec7c96f
'
This commit is contained in:
commit
d19ed4d4e6
810 changed files with 24147 additions and 7766 deletions
|
@ -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 "" }} → .
|
||||
```
|
||||
|
|
|
@ -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 "" }} → .
|
||||
```
|
||||
|
|
|
@ -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.
|
||||
|
||||
[`path.Clean`]: https://pkg.go.dev/path#Clean
|
||||
|
||||
```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:
|
||||
|
||||
```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 "" }} → .
|
||||
```
|
||||
|
|
|
@ -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 "" }} → .
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
12
docs/content/en/functions/path/_index.md
Normal file
12
docs/content/en/functions/path/_index.md
Normal file
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue