diff --git a/content/en/functions/path.Base.md b/content/en/functions/path.Base.md new file mode 100644 index 000000000..87eb67355 --- /dev/null +++ b/content/en/functions/path.Base.md @@ -0,0 +1,31 @@ +--- +title: path.Base +description: Base returns the last element of a path. +godocref: +date: 2018-11-28 +publishdate: 2018-11-28 +lastmod: 2018-11-28 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [path, base] +signature: ["path.Base PATH"] +workson: [] +hugoversion: "0.40" +relatedfuncs: [path.Dir, path.Ext, path.Split] +deprecated: false +--- + +`path.Base` returns the last element of `PATH`. + +If `PATH` is empty, `.` is returned. + +**Note:** On Windows, `PATH` is converted to slash (`/`) separators. + +``` +{{ 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" +``` diff --git a/content/en/functions/path.Dir.md b/content/en/functions/path.Dir.md new file mode 100644 index 000000000..54a3fb8be --- /dev/null +++ b/content/en/functions/path.Dir.md @@ -0,0 +1,32 @@ +--- +title: path.Dir +description: Dir returns all but the last element of a path. +godocref: +date: 2018-11-28 +publishdate: 2018-11-28 +lastmod: 2018-11-28 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [path, dir] +signature: ["path.Dir PATH"] +workson: [] +hugoversion: "0.40" +relatedfuncs: [path.Base, path.Ext, path.Split] +deprecated: false +--- + +`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. + +``` +{{ path.Dir "a/news.html" }} → "a" +{{ path.Dir "news.html" }} → "." +{{ path.Dir "a/b/c" }} → "a/b" +{{ path.Dir "/x/y/z" }} → "/x/y" +``` diff --git a/content/en/functions/path.Ext.md b/content/en/functions/path.Ext.md new file mode 100644 index 000000000..a36b006f3 --- /dev/null +++ b/content/en/functions/path.Ext.md @@ -0,0 +1,29 @@ +--- +title: path.Ext +description: Ext returns the file name extension of a path. +godocref: +date: 2018-11-28 +publishdate: 2018-11-28 +lastmod: 2018-11-28 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [path, ext, extension] +signature: ["path.Ext PATH"] +workson: [] +hugoversion: "0.40" +relatedfuncs: [path.Base, path.Dir, path.Split] +deprecated: false +--- + +`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. + +``` +{{ path.Ext "a/b/c/news.html" }} → ".html" +``` diff --git a/content/en/functions/path.Join.md b/content/en/functions/path.Join.md new file mode 100644 index 000000000..06a8121f0 --- /dev/null +++ b/content/en/functions/path.Join.md @@ -0,0 +1,29 @@ +--- +title: path.Join +description: Join path elements into a single path. +godocref: +date: 2018-11-28 +publishdate: 2018-11-28 +lastmod: 2018-11-28 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [path, join] +signature: ["path.Join ELEMENT..."] +workson: [] +hugoversion: "0.39" +relatedfuncs: [path.Split] +deprecated: false +--- + +`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. + +``` +{{ path.Join "partial" "news.html" }} → "partial/news.html" +{{ path.Join "partial/" "news.html" }} → "partial/news.html" +{{ path.Join "foo/baz" "bar" }} → "foo/baz/bar" +``` diff --git a/content/en/functions/path.Split.md b/content/en/functions/path.Split.md new file mode 100644 index 000000000..d6bc15ce9 --- /dev/null +++ b/content/en/functions/path.Split.md @@ -0,0 +1,31 @@ +--- +title: path.Split +description: Split path immediately following the final slash. +godocref: +date: 2018-11-28 +publishdate: 2018-11-28 +lastmod: 2018-11-28 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [path, split] +signature: ["path.Split PATH"] +workson: [] +hugoversion: "0.39" +relatedfuncs: [path.Split] +deprecated: false +--- + +`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. + +``` +{{ path.Split "a/news.html" }} → "a/", "news.html" +{{ path.Split "news.html" }} → "", "news.html" +{{ path.Split "a/b/c" }} → "a/b/", "c" +```