Add support for .Hugo.Environment variable (#453)

This commit is contained in:
Troy Lindsay 2021-12-12 13:39:21 -06:00
parent c7b9901e01
commit eb2ef5dc31
No known key found for this signature in database
GPG Key ID: C82B6E26104FA540
4 changed files with 14 additions and 7 deletions

View File

@ -274,19 +274,26 @@ Now enter [`localhost:1313`](http://localhost:1313/) in the address bar of your
## Production ## Production
To run in production (e.g. to have Google Analytics show up), run `HUGO_ENV=production` before your build command. For example: To run in production (e.g. to have Google Analytics show up), the built-in [Hugo variable: Environment (`.Hugo.Environment`)](https://gohugo.io/variables/hugo/) will default to `production` when running `hugo` to build the site (whereas `hugo server` defaults to `development`), or this can be configured explicitly via the CLI-tag via `hugo --environment 'production'`, or run `HUGO_ENV=production` before your build command. For example:
``` ```
HUGO_ENV=production hugo HUGO_ENV=production hugo
``` ```
Note: The above command will not work on Windows. If you are running a Windows OS, use the below command: Note: The above command will not work on Windows. If you are running a Windows OS, use the below command if using the command shell:
``` ```bat
set HUGO_ENV=production set HUGO_ENV=production
hugo hugo
``` ```
...or the following if using PowerShell:
```powershell
$env:HUGO_ENV='production'
hugo
```
## Contributing ## Contributing
If you find a bug or have an idea for a feature, feel free to use the [issue tracker](https://github.com/theNewDynamic/gohugo-theme-ananke/issues) to let me know. If you find a bug or have an idea for a feature, feel free to use the [issue tracker](https://github.com/theNewDynamic/gohugo-theme-ananke/issues) to let me know.

View File

@ -9,7 +9,7 @@
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"> <meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
{{ hugo.Generator }} {{ hugo.Generator }}
{{/* NOTE: For Production make sure you add `HUGO_ENV="production"` before your build command */}} {{/* NOTE: For Production make sure you add `HUGO_ENV="production"` before your build command */}}
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }} {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") | or (eq .Hugo.Environment "production") }}
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW"> <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
{{ else }} {{ else }}
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
@ -33,7 +33,7 @@
{{- template "_internal/schema.html" . -}} {{- template "_internal/schema.html" . -}}
{{- template "_internal/twitter_cards.html" . -}} {{- template "_internal/twitter_cards.html" . -}}
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }} {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") | or (eq .Hugo.Environment "production") }}
{{ template "_internal/google_analytics_async.html" . }} {{ template "_internal/google_analytics_async.html" . }}
{{ end }} {{ end }}
{{ block "head" . }}{{ partial "head-additions.html" . }}{{ end }} {{ block "head" . }}{{ partial "head-additions.html" . }}{{ end }}

View File

@ -59,7 +59,7 @@ css asset directory we add to aforementioned slice */}}
{{ $options := dict "enableSourceMap" true "precision" 6 }} {{ $options := dict "enableSourceMap" true "precision" 6 }}
{{ $style = $style | resources.ToCSS $options | minify }} {{ $style = $style | resources.ToCSS $options | minify }}
{{/* We fingerprint in production for cache busting purposes */}} {{/* We fingerprint in production for cache busting purposes */}}
{{ if eq (getenv "HUGO_ENV") "production" }} {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") | or (eq .Hugo.Environment "production") }}
{{ $style = $style | fingerprint }} {{ $style = $style | fingerprint }}
{{ end }} {{ end }}
{{/* We're ready to set returning variable with resulting resource */}} {{/* We're ready to set returning variable with resulting resource */}}

View File

@ -1,6 +1,6 @@
User-agent: * User-agent: *
# robotstxt.org - if ENV production variable is false robots will be disallowed. # robotstxt.org - if ENV production variable is false robots will be disallowed.
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }} {{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") | or (eq .Hugo.Environment "production") }}
Allow: / Allow: /
Sitemap: {{.Site.BaseURL}}/sitemap.xml Sitemap: {{.Site.BaseURL}}/sitemap.xml
{{ else }} {{ else }}