mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'
This commit is contained in:
35
docs/content/en/functions/path/Base.md
Normal file
35
docs/content/en/functions/path/Base.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: path.Base
|
||||
description: Base returns the last element of a path.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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"
|
||||
```
|
33
docs/content/en/functions/path/BaseName.md
Normal file
33
docs/content/en/functions/path/BaseName.md
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: path.BaseName
|
||||
description: BaseName returns the last element of a path, removing the extension if present.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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.
|
||||
|
||||
```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"
|
||||
```
|
35
docs/content/en/functions/path/Clean.md
Normal file
35
docs/content/en/functions/path/Clean.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: path.Clean
|
||||
description: Replaces path separators with slashes (`/`) and removes extraneous separators.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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.
|
||||
|
||||
```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"
|
||||
```
|
36
docs/content/en/functions/path/Dir.md
Normal file
36
docs/content/en/functions/path/Dir.md
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: path.Dir
|
||||
description: Dir returns all but the last element of a path.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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"
|
||||
```
|
33
docs/content/en/functions/path/Ext.md
Normal file
33
docs/content/en/functions/path/Ext.md
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
title: path.Ext
|
||||
description: Ext returns the file name extension of a path.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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.
|
||||
|
||||
```go-html-template
|
||||
{{ path.Ext "a/b/c/news.html" }} → ".html"
|
||||
```
|
34
docs/content/en/functions/path/Join.md
Normal file
34
docs/content/en/functions/path/Join.md
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
title: path.Join
|
||||
description: Join path elements into a single path.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
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.
|
||||
|
||||
**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"
|
||||
```
|
43
docs/content/en/functions/path/Split.md
Normal file
43
docs/content/en/functions/path/Split.md
Normal file
@@ -0,0 +1,43 @@
|
||||
---
|
||||
title: path.Split
|
||||
description: Split path immediately following the final slash.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
returnType: 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.
|
||||
|
||||
```go-html-template
|
||||
{{ $dirFile := path.Split "a/news.html" }}
|
||||
{{ $dirFile.Dir }} → "a/"
|
||||
{{ $dirFile.File }} → "news.html"
|
||||
|
||||
{{ $dirFile := path.Split "news.html" }}
|
||||
{{ $dirFile.Dir }} → ""
|
||||
{{ $dirFile.File }} → "news.html"
|
||||
|
||||
{{ $dirFile := path.Split "a/b/c" }}
|
||||
{{ $dirFile.Dir }} → "a/b/"
|
||||
{{ $dirFile.File }} → "c"
|
||||
```
|
Reference in New Issue
Block a user