Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'

This commit is contained in:
Bjørn Erik Pedersen
2023-12-04 15:24:01 +01:00
810 changed files with 24147 additions and 7766 deletions

View File

@@ -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
```

View File

@@ -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.

View File

@@ -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 }}
```

View File

@@ -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:

View File

@@ -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]
---

View File

@@ -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.