theme(fix): use internal methods to evaluate environment

closes #625
closes #733
closes #453
closes #574

Signed-off-by: Patrick Kollitsch <patrick@davids-neighbour.com>
This commit is contained in:
Patrick Kollitsch 2024-10-21 10:01:01 +07:00
parent 9332bad766
commit cc6da237ea
No known key found for this signature in database
GPG key ID: 5A5360B005AD68C7
3 changed files with 7 additions and 6 deletions

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 */}}
{{ $production := eq (getenv "HUGO_ENV") "production" | or (eq site.Params.env "production") }} {{ $production := hugo.IsProduction }}
{{ $public := not .Params.private }} {{ $public := not .Params.private }}
{{ if and $production $public }} {{ if and $production $public }}
<meta name="robots" content="index, follow"> <meta name="robots" content="index, follow">
@ -51,13 +51,14 @@
{{- 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 hugo.IsProduction }}
{{ template "_internal/google_analytics.html" . }} {{ template "_internal/google_analytics.html" . }}
{{ end }} {{ end }}
{{ block "head" . }}{{ partial "head-additions.html" . }}{{ end }} {{ block "head" . }}{{ partial "head-additions.html" . }}{{ end }}
</head> </head>
<body class="ma0 {{ $.Param "body_classes" | default "avenir bg-near-white"}}{{ with getenv "HUGO_ENV" }} {{ . }}{{ end }}"> {{- $environment := hugo.Environment | default "production" -}}
<body class="ma0 {{ $.Param "body_classes" | default "avenir bg-near-white"}} {{ $environment }}">
{{ block "header" . }}{{ partial "site-header.html" .}}{{ end }} {{ block "header" . }}{{ partial "site-header.html" .}}{{ end }}
<main class="pb7" role="main"> <main class="pb7" role="main">

View file

@ -70,7 +70,7 @@ css asset directory we (unless condition below) add to aforementioned slice */}}
{{ $options := dict "enableSourceMap" true "precision" 6 }} {{ $options := dict "enableSourceMap" true "precision" 6 }}
{{ $style = $style | css.Sass $options | minify }} {{ $style = $style | css.Sass $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 hugo.IsProduction }}
{{ $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 we are in production, allow access, else deny */ -}}
{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") -}} {{ if hugo.IsProduction -}}
Allow: / Allow: /
Sitemap: {{ "/sitemap.xml" | absURL }} Sitemap: {{ "/sitemap.xml" | absURL }}
{{ else -}} {{ else -}}