From 2dfe0d1c30b5cd56a715ee676c755376ee190550 Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Tue, 7 Dec 2021 14:16:55 +0000 Subject: [PATCH 1/2] Make only live website indexable This change updates how we run Hugo AND changes the logic for checking whether a page should be indexable (copied with a backport from upstream Docsy). --- Makefile | 24 +++++++++++++----------- layouts/index.headers | 2 +- layouts/partials/head.html | 13 +++++++------ netlify.toml | 13 +++---------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index a103f4e58e..984c261466 100644 --- a/Makefile +++ b/Makefile @@ -28,14 +28,14 @@ module-init: all: build ## Build site with production settings and put deliverables in ./public -build: module-check ## Build site with production settings and put deliverables in ./public - hugo --minify +build: module-check ## Build site with non-production settings and put deliverables in ./public + hugo --minify --environment development build-preview: module-check ## Build site with drafts and future posts enabled - hugo --buildDrafts --buildFuture + hugo --buildDrafts --buildFuture --environment preview deploy-preview: ## Deploy preview site via netlify - hugo --enableGitInfo --buildFuture -b $(DEPLOY_PRIME_URL) + hugo --enableGitInfo --buildFuture --environment preview -b $(DEPLOY_PRIME_URL) functions-build: $(NETLIFY_FUNC) build functions-src @@ -43,13 +43,15 @@ functions-build: check-headers-file: scripts/check-headers-file.sh -production-build: build check-headers-file ## Build the production site and ensure that noindex headers aren't added +production-build: module-check ## Build the production site and ensure that noindex headers aren't added + hugo --minify --environment production + HUGO_ENV=production $(MAKE) check-headers-file -non-production-build: ## Build the non-production site, which adds noindex headers to prevent indexing - hugo --enableGitInfo +non-production-build: module-check ## Build the non-production site, which adds noindex headers to prevent indexing + hugo --enableGitInfo --environment nonprod serve: module-check ## Boot the development server. - hugo server --buildFuture + hugo server --buildFuture --environment development docker-image: @echo -e "$(CCRED)**** The use of docker-image is deprecated. Use container-image instead. ****$(CCEND)" @@ -70,10 +72,10 @@ container-image: ## Build a container image for the preview of the website --build-arg HUGO_VERSION=$(HUGO_VERSION) container-build: module-check - $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify" + $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development" container-serve: module-check ## Boot the development server using container. Run `make container-image` before this. - $(CONTAINER_RUN) --cap-drop=ALL --cap-add=AUDIT_WRITE --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 -p 1313:1313 $(CONTAINER_IMAGE) hugo server --buildFuture --bind 0.0.0.0 --destination /tmp/hugo --cleanDestinationDir + $(CONTAINER_RUN) --cap-drop=ALL --cap-add=AUDIT_WRITE --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 -p 1313:1313 $(CONTAINER_IMAGE) hugo server --buildFuture --environment development --bind 0.0.0.0 --destination /tmp/hugo --cleanDestinationDir test-examples: scripts/test_examples.sh install @@ -88,7 +90,7 @@ docker-internal-linkcheck: $(MAKE) container-internal-linkcheck container-internal-linkcheck: link-checker-image-pull - $(CONTAINER_RUN) $(CONTAINER_IMAGE) hugo --config config.toml,linkcheck-config.toml --buildFuture + $(CONTAINER_RUN) $(CONTAINER_IMAGE) hugo --config config.toml,linkcheck-config.toml --buildFuture --environment test $(CONTAINER_ENGINE) run --mount type=bind,source=$(CURDIR),target=/test --rm wjdp/htmltest htmltest clean-api-reference: ## Clean all directories in API reference directory, preserve _index.md diff --git a/layouts/index.headers b/layouts/index.headers index 2402097ae6..aecac14e3d 100644 --- a/layouts/index.headers +++ b/layouts/index.headers @@ -1,4 +1,4 @@ -{{- if eq (getenv "HUGO_ENV") "production" }} +{{- if eq hugo.Environment "production" }} {{- $cssFilesFromConfig := site.Params.pushAssets.css -}} {{- $jsFilesFromConfig := site.Params.pushAssets.js -}} {{- $pages := site.RegularPages -}} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index c15f9ba05d..9f25090d63 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,5 +1,11 @@ {{- $isBlogPost := eq .Section "blog" }} {{- $ogType := cond (.IsHome) "website" "article" }} + +{{- if hugo.IsProduction -}} + +{{- else -}} + +{{- end -}}