diff options
Diffstat (limited to 'docs/content/en/functions/os')
-rw-r--r-- | docs/content/en/functions/os/FileExists.md | 33 | ||||
-rw-r--r-- | docs/content/en/functions/os/Getenv.md | 52 | ||||
-rw-r--r-- | docs/content/en/functions/os/ReadDir.md | 23 | ||||
-rw-r--r-- | docs/content/en/functions/os/ReadFile.md | 21 | ||||
-rw-r--r-- | docs/content/en/functions/os/Stat.md | 20 | ||||
-rw-r--r-- | docs/content/en/functions/os/_index.md | 12 |
6 files changed, 83 insertions, 78 deletions
diff --git a/docs/content/en/functions/os/FileExists.md b/docs/content/en/functions/os/FileExists.md index 52cfe32c8..b8104a066 100644 --- a/docs/content/en/functions/os/FileExists.md +++ b/docs/content/en/functions/os/FileExists.md @@ -1,22 +1,17 @@ --- title: os.FileExists -linkTitle: fileExists description: Reports whether the file or directory exists. -categories: [functions] +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [fileExists] + related: + - functions/os/Getenv + - functions/os/ReadDir + - functions/os/ReadFile + - functions/os/Stat returnType: bool signatures: [os.FileExists PATH] -relatedFunctions: - - os.FileExists - - os.Getenv - - os.ReadDir - - os.ReadFile - - os.Stat aliases: [/functions/fileexists] --- @@ -36,11 +31,11 @@ content/ The function returns these values: ```go-html-template -{{ os.FileExists "content" }} → true -{{ os.FileExists "content/news" }} → true -{{ os.FileExists "content/news/article-1" }} → false -{{ os.FileExists "content/news/article-1.md" }} → true -{{ os.FileExists "news" }} → true -{{ os.FileExists "news/article-1" }} → false -{{ os.FileExists "news/article-1.md" }} → true +{{ fileExists "content" }} → true +{{ fileExists "content/news" }} → true +{{ fileExists "content/news/article-1" }} → false +{{ fileExists "content/news/article-1.md" }} → true +{{ fileExists "news" }} → true +{{ fileExists "news/article-1" }} → false +{{ fileExists "news/article-1.md" }} → true ``` diff --git a/docs/content/en/functions/os/Getenv.md b/docs/content/en/functions/os/Getenv.md index 16f73f5aa..084d498ce 100644 --- a/docs/content/en/functions/os/Getenv.md +++ b/docs/content/en/functions/os/Getenv.md @@ -1,35 +1,49 @@ --- title: os.Getenv -linkTitle: getenv description: Returns the value of an environment variable, or an empty string if the environment variable is not set. -categories: [functions] +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [getenv] + related: + - functions/os/FileExists + - functions/os/ReadDir + - functions/os/ReadFile + - functions/os/Stat returnType: string signatures: [os.Getenv VARIABLE] -relatedFunctions: - - os.FileExists - - os.Getenv - - os.ReadDir - - os.ReadFile - - os.Stat aliases: [/functions/getenv] +toc: true --- -Examples: +## Security + +By default, when using the `os.Getenv` function Hugo allows access to: + +- The `CI` environment variable +- Any environment variable beginning with `HUGO_` + +To access other environment variables, adjust your site configuration. For example, to allow access to the `HOME` and `USER` environment variables: + +{{< code-toggle file=hugo >}} +[security.funcs] +getenv = ['^HUGO_', '^CI$', '^USER$', '^HOME$'] +{{< /code-toggle >}} + +Read more about Hugo's [security policy]. + +[security policy]: /about/security-model/#security-policy + +## Examples ```go-html-template -{{ os.Getenv "HOME" }} → /home/victor -{{ os.Getenv "USER" }} → victor +{{ getenv "HOME" }} → /home/victor +{{ getenv "USER" }} → victor ``` You can pass values when building your site: -```bash +```sh MY_VAR1=foo MY_VAR2=bar hugo OR @@ -42,8 +56,6 @@ hugo And then retrieve the values within a template: ```go-html-template -{{ os.Getenv "MY_VAR1" }} → foo -{{ os.Getenv "MY_VAR2" }} → bar +{{ getenv "MY_VAR1" }} → foo +{{ getenv "MY_VAR2" }} → bar ``` - -With Hugo v0.91.0 and later, you must explicitly allow access to environment variables. For details, review [Hugo's Security Policy](/about/security-model/#security-policy). By default, environment variables beginning with `HUGO_` are allowed when using the `os.Getenv` function. diff --git a/docs/content/en/functions/os/ReadDir.md b/docs/content/en/functions/os/ReadDir.md index d0ed87bdf..63af850b7 100644 --- a/docs/content/en/functions/os/ReadDir.md +++ b/docs/content/en/functions/os/ReadDir.md @@ -1,22 +1,17 @@ --- title: os.ReadDir -linkTitle: readDir description: Returns an array of FileInfo structures sorted by file name, one element for each directory entry. -categories: [functions] +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [readDir] - returnType: FileInfo + related: + - functions/os/FileExists + - functions/os/Getenv + - functions/os/ReadFile + - functions/os/Stat + returnType: os.FileInfo signatures: [os.ReadDir PATH] -relatedFunctions: - - os.FileExists - - os.Getenv - - os.ReadDir - - os.ReadFile - - os.Stat aliases: [/functions/readdir] --- @@ -36,7 +31,7 @@ content/ This template code: ```go-html-template -{{ range os.ReadDir "content" }} +{{ range readDir "content" }} {{ .Name }} → {{ .IsDir }} {{ end }} ``` diff --git a/docs/content/en/functions/os/ReadFile.md b/docs/content/en/functions/os/ReadFile.md index 30f2b3056..654e300ac 100644 --- a/docs/content/en/functions/os/ReadFile.md +++ b/docs/content/en/functions/os/ReadFile.md @@ -1,22 +1,17 @@ --- title: os.ReadFile -linkTitle: readFile description: Returns the contents of a file. -categories: [functions] +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [readFile] + related: + - functions/os/FileExists + - functions/os/Getenv + - functions/os/ReadDir + - functions/os/Stat returnType: string signatures: [os.ReadFile PATH] -relatedFunctions: - - os.FileExists - - os.Getenv - - os.ReadDir - - os.ReadFile - - os.Stat aliases: [/functions/readfile] --- @@ -31,7 +26,7 @@ This is **bold** text. This template code: ```go-html-template -{{ os.ReadFile "README.md" }} +{{ readFile "README.md" }} ``` Produces: diff --git a/docs/content/en/functions/os/Stat.md b/docs/content/en/functions/os/Stat.md index dfef3c815..6b6f668de 100644 --- a/docs/content/en/functions/os/Stat.md +++ b/docs/content/en/functions/os/Stat.md @@ -1,21 +1,17 @@ --- title: os.Stat description: Returns a FileInfo structure describing a file or directory. -categories: [functions] +categories: [] keywords: [] -menu: - docs: - parent: functions -function: +action: aliases: [] - returnType: FileInfo + related: + - functions/os/FileExists + - functions/os/Getenv + - functions/os/ReadDir + - functions/os/ReadFile + returnType: os.FileInfo signatures: [os.Stat PATH] -relatedFunctions: - - os.FileExists - - os.Getenv - - os.ReadDir - - os.ReadFile - - os.Stat aliases: [/functions/os.stat] --- diff --git a/docs/content/en/functions/os/_index.md b/docs/content/en/functions/os/_index.md new file mode 100644 index 000000000..c080d0092 --- /dev/null +++ b/docs/content/en/functions/os/_index.md @@ -0,0 +1,12 @@ +--- +title: OS functions +linkTitle: os +description: Template functions to interact with the operating system. +categories: [] +keywords: [] +menu: + docs: + parent: functions +--- + +Use these functions to interact with the operating system. |