-
Notifications
You must be signed in to change notification settings - Fork 1
Env
HUGE/Env is responsible of everything environment. Its public functions are available to any user.
HUGE/Env relies on its huge/env/Get function detailed below to determine the environment. As is, it's just a wrapper for hugo.Environment. huge/env/GetVar on the other hand is a helpful function to retrieve the value of an environment variable with a fall back on local environments.
-
hugo.Environmentreturns the value of - the
--environment(or-e) flag set through Hugo CLI or, - if not set,
HUGO_ENVorHUGO_ENVIRONMENTenvironment variable. - If none of the above are set it returns
developmentin server mode, - and
productionin build mode.
In case of conflicts between HUGO_ENV/HUGO_ENVIRONMENT and the --environment flag, and contrary to Hugo, HUGE will always use the value of HUGO_ENV/HUGO_ENVIRONMENT.
TL;DR
| command | hugo.Environment |
huge/env/Get |
|---|---|---|
| huge server | development | development |
| hugo -e production | production | production |
| HUGO_ENV=production hugo | production | production |
| HUGO_ENV=production hugo -e cloudflare | cloudflare | production |
If the project relies on another logic than HUGE's to determine its environment, one can add its own partial at layouts/partials/huge/env/Get, it will overrides HUGE's.
Let's say the project relies on NODE_ENV for determining environment.
{{/* /layouts/partials/huge/env/Get */}}
{{ $env := hugo.Environment }}
{{ with getenv "NODE_ENV" }}
{{ $env = . }}
{{ end }}
{{ return $env }}Now huge/env/Get and other HUGE/Env functions will also rely on NODE_ENV to evaluate.
HUGE/Env also provides a helper function to retrieve environment variables which gracefully fallbacks on any key added to _huge/config/env.yaml if no "real" environment variable is found.
It is useful for working locally with a gitignored file similar to dotenv's .env logic:
#_huge/config/env.yaml
SECRET_API_KEY: 13derxxxxxxxxxx234
API_UR: https//api.here.com/Lengthily discussed above.
Any
A string representing the current environment. Logic is discussed above.
{{ if eq (partial "huge/env/Get") "development" }}
{{ $debug = true }}
{{ end }}A string.
A boolean, true if the given string matches the current environment, false if not.
{{ if partial "huge/env/Is" "production" }}
{{ $ga = true}}
{{ end }}A string.
A boolean, true if the given string does not match the current environment, false if it does.
{{ if partial "huge/env/IsNot" "production" }}
{{ $debug = true }}
{{ end }}Any
A boolean, true if the current environment matches production, false if not.
{{ if partial "huge/env/IsProduction" "production" }}
{{ $debug = true }}
{{ end }}This is handy when you need to do something always or never or only in one or several given environment.
A string which must be among a list of:
alwaysnever-
{environment}: A string representing one of the project's environments. It will be tested against the current environment.
OR a slice of strings whose strings will be tested against the current environment.
A boolean:
true if the given parameter is always or matches or contains the current environment.
false if the given parameter is never or do not match or do not contain the current environment.
Returns the value of the environment variable matching a given key. If none is found, falls back to the value of the given key as stored in _huge/config/env.yaml.
String
A string representing the key of an environment variable.
{{ with partial "huge/env/GetVar" "API_KEY" }}
{{ $data = resources.GetRemote (printf "https://api.endpoint/%s/data/" . }}
{{ end }}This is a HUGE WIP right now! Stay tune for more info as we push it to Alpha!