From cc6da237ea3e659a19be8faaa0f365898b5b878f Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <patrick@davids-neighbour.com>
Date: Mon, 21 Oct 2024 03:03:45 +0000
Subject: [PATCH] theme(fix): use internal methods to evaluate environment

---
 layouts/_default/baseof.html                |    7 ++++---
 layouts/partials/func/style/GetMainCSS.html |    2 +-
 layouts/robots.txt                          |    4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 2d6f836..30744c4 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -9,7 +9,7 @@
     <meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
     {{ hugo.Generator }}
     {{/* 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 }}
     {{ if and $production $public }}
       <meta name="robots" content="index, follow">
@@ -51,13 +51,14 @@
     {{- template "_internal/schema.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" . }}
     {{ end }}
 	{{ block "head" . }}{{ partial "head-additions.html" . }}{{ end }}
   </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 }}
     <main class="pb7" role="main">
diff --git a/layouts/partials/func/style/GetMainCSS.html b/layouts/partials/func/style/GetMainCSS.html
index a6f68ae..2853790 100644
--- a/layouts/partials/func/style/GetMainCSS.html
+++ b/layouts/partials/func/style/GetMainCSS.html
@@ -70,7 +70,7 @@
   {{ $options := dict "enableSourceMap" true "precision" 6 }}
   {{ $style = $style | css.Sass $options | minify }}
   {{/* We fingerprint in production for cache busting purposes */}}
-  {{ if eq (getenv "HUGO_ENV") "production" }}
+  {{ if hugo.IsProduction }}
     {{ $style = $style | fingerprint }}
   {{ end }}
   {{/* We're ready to set returning variable with resulting resource */}}
diff --git a/layouts/robots.txt b/layouts/robots.txt
index d4efb29..a1069a4 100644
--- a/layouts/robots.txt
+++ b/layouts/robots.txt
@@ -1,6 +1,6 @@
 User-agent: *
-{{/* robotstxt.org - if ENV production variable is false robots will be disallowed. */ -}}
-{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production")  -}}
+{{/* robotstxt.org - if we are in production, allow access, else deny */ -}}
+{{ if hugo.IsProduction -}}
 Allow: /
 Sitemap: {{ "/sitemap.xml" | absURL }}
 {{ else -}}

--
Gitblit v1.10.0