mirror of
https://github.com/theNewDynamic/gohugo-theme-ananke.git
synced 2025-06-08 17:22:46 +00:00
* Adds GetEnvironmentName and IsProduction partial functions, which improve DRY * Add prioritization for determining environment name, which favors the existing methods: the `HUGO_ENV` environment variable and site config `env` theme parameter * Adds `useHugoEnv` theme parameter to use the value of `.Hugo.Environment` for the build environment name
36 lines
1.1 KiB
HTML
36 lines
1.1 KiB
HTML
{{/*
|
|
GetEnvironmentName
|
|
|
|
This partial returns either the configured or the default build environment
|
|
name.
|
|
|
|
The four options for setting the build environment name (ordered by priority)
|
|
are:
|
|
1. The "HUGO_ENV" environment variable.
|
|
2. The "env" site config theme parameter.
|
|
3. Setting the "useHugoEnv" site config theme parameter to true, which will
|
|
use the value of ".Hugo.Environment" for the build environment name.
|
|
|
|
The default environment name for the "hugo server" command is
|
|
"development", and the default for the "hugo" build command is
|
|
"production". The environment name can be configured via the
|
|
"--environment" flag, such as "hugo --environment test".
|
|
4. Use the default build environment name.
|
|
|
|
@return build environment name.
|
|
*/}}
|
|
|
|
{{ $env := "development" }}
|
|
{{ $site := site }}
|
|
{{ $hugo := hugo }}
|
|
|
|
{{ if (getenv "HUGO_ENV") }}
|
|
{{ $env = getenv "HUGO_ENV" }}
|
|
{{ else if $site.Params.env }}
|
|
{{ $env = $site.Params.env }}
|
|
{{ else if (eq $site.Params.useHugoEnv true) }}
|
|
{{ $env = $hugo.Environment }}
|
|
{{ end }}
|
|
|
|
{{ return $env }}
|