Skip to content

Commit

Permalink
Use hugo.Environment instead of getenv
Browse files Browse the repository at this point in the history
This is set automatically to "development" when the local server is running, and to "production" when Hugo builds the site.
  • Loading branch information
XhmikosR committed Oct 8, 2019
1 parent 1770691 commit 3ecfad0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -50,20 +50,19 @@
"docs": "npm-run-all docs-build docs-lint",
"docs-build": "hugo --cleanDestinationDir",
"docs-compile": "npm run docs-build",
"docs-production": "cross-env HUGO_ENV=production npm run docs-build",
"docs-linkinator": "linkinator _gh_pages --recurse --silent --skip \"^(?!http://localhost)\"",
"docs-vnu": "node build/vnu-jar.js",
"docs-lint": "npm-run-all --parallel docs-vnu docs-linkinator",
"docs-serve": "hugo server --port 9001 --disableFastRender",
"docs-serve-only": "serve _gh_pages --listen 9001",
"update-deps": "ncu -a -x karma-browserstack-launcher && npm update && shx echo Manually update site/assets/js/vendor",
"release": "npm-run-all dist release-sri release-zip docs-production",
"release": "npm-run-all dist release-sri release-zip docs-build",
"release-sri": "node build/generate-sri.js",
"release-version": "node build/change-version.js",
"release-zip": "cross-env-shell \"shx rm -rf bootstrap-$npm_package_version-dist && shx cp -r dist/ bootstrap-$npm_package_version-dist && zip -r9 bootstrap-$npm_package_version-dist.zip bootstrap-$npm_package_version-dist && shx rm -rf bootstrap-$npm_package_version-dist\"",
"dist": "npm-run-all --parallel css js",
"test": "npm-run-all lint dist js-test docs-build docs-lint",
"netlify": "npm-run-all dist release-sri docs-production",
"netlify": "npm-run-all dist release-sri docs-build",
"watch": "npm-run-all --parallel watch-*",
"watch-css-main": "nodemon --watch scss/ --ext scss --exec \"npm-run-all css-lint css-compile css-prefix\"",
"watch-css-docs": "nodemon --watch site/assets/scss/ --ext scss --exec \"npm run css-lint\"",
Expand Down
2 changes: 1 addition & 1 deletion site/layouts/_default/examples.html
Expand Up @@ -43,7 +43,7 @@
{{ .Content }}

{{ if ne .Page.Params.include_js false -}}
{{- if eq (getenv "HUGO_ENV") "production" -}}
{{- if eq hugo.Environment "production" -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" integrity="{{ .Site.Params.cdn.js_bundle_hash }}" crossorigin="anonymous"></script>
{{- else -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions site/layouts/partials/scripts.html
@@ -1,4 +1,4 @@
{{ if eq (getenv "HUGO_ENV") "production" -}}
{{ if eq hugo.Environment "production" -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.min.js" integrity="{{ .Site.Params.cdn.js_bundle_hash }}" crossorigin="anonymous"></script>
{{ else -}}
<script src="/docs/{{ .Site.Params.docs_version }}/dist/js/bootstrap.bundle.js"></script>
Expand All @@ -13,7 +13,7 @@
{{- $targetDocsJSPath := printf "/docs/%s/assets/js/docs.js" .Site.Params.docs_version -}}
{{- $docsJs := append $js $vendor | resources.Concat $targetDocsJSPath -}}

{{- if (eq (getenv "HUGO_ENV") "production") -}}
{{- if eq hugo.Environment "production" -}}
{{- $docsJs = $docsJs | resources.Minify -}}
{{- end }}

Expand Down
4 changes: 2 additions & 2 deletions site/layouts/partials/stylesheet.html
@@ -1,5 +1,5 @@
{{- "<!-- Bootstrap core CSS -->" | safeHTML }}
{{ if eq (getenv "HUGO_ENV") "production" -}}
{{ if eq hugo.Environment "production" -}}
<link href="/docs/{{ .Site.Params.docs_version }}/dist/css/bootstrap.min.css" rel="stylesheet" integrity="{{ .Site.Params.cdn.css_hash }}" crossorigin="anonymous">
{{- else -}}
<link href="/docs/{{ .Site.Params.docs_version }}/dist/css/bootstrap.css" rel="stylesheet">
Expand All @@ -15,7 +15,7 @@
{{- $sassOptions := dict "targetPath" $targetDocsCssPath "precision" 6 -}}
{{- $postcssOptions := dict "use" "autoprefixer" "noMap" true -}}

{{- if (eq (getenv "HUGO_ENV") "production") -}}
{{ if eq hugo.Environment "production" -}}
{{- $sassOptions = merge $sassOptions (dict "outputStyle" "compressed") -}}
{{- end -}}

Expand Down
2 changes: 1 addition & 1 deletion site/layouts/robots.txt
@@ -1,6 +1,6 @@
# www.robotstxt.org

{{- $isProduction := eq (getenv "HUGO_ENV") "production" -}}
{{- $isProduction := eq hugo.Environment "production" -}}
{{- $isNetlify := eq (getenv "NETLIFY") "true" -}}
{{- $allowCrawling := and (not $isNetlify) $isProduction -}}

Expand Down

0 comments on commit 3ecfad0

Please sign in to comment.