Skip to content

Commit 953bb28

Browse files
authored
Merge pull request #30790 from sftim/20211207_mark_only_live_site_indexable
Make only live website indexable
2 parents 9bdb086 + 4592cf5 commit 953bb28

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,30 @@ module-init:
2828

2929
all: build ## Build site with production settings and put deliverables in ./public
3030

31-
build: module-check ## Build site with production settings and put deliverables in ./public
32-
hugo --minify
31+
build: module-check ## Build site with non-production settings and put deliverables in ./public
32+
hugo --minify --environment development
3333

3434
build-preview: module-check ## Build site with drafts and future posts enabled
35-
hugo --buildDrafts --buildFuture
35+
hugo --buildDrafts --buildFuture --environment preview
3636

3737
deploy-preview: ## Deploy preview site via netlify
38-
hugo --enableGitInfo --buildFuture -b $(DEPLOY_PRIME_URL)
38+
hugo --enableGitInfo --buildFuture --environment preview -b $(DEPLOY_PRIME_URL)
3939

4040
functions-build:
4141
$(NETLIFY_FUNC) build functions-src
4242

4343
check-headers-file:
4444
scripts/check-headers-file.sh
4545

46-
production-build: build check-headers-file ## Build the production site and ensure that noindex headers aren't added
46+
production-build: module-check ## Build the production site and ensure that noindex headers aren't added
47+
hugo --minify --environment production
48+
HUGO_ENV=production $(MAKE) check-headers-file
4749

48-
non-production-build: ## Build the non-production site, which adds noindex headers to prevent indexing
49-
hugo --enableGitInfo
50+
non-production-build: module-check ## Build the non-production site, which adds noindex headers to prevent indexing
51+
hugo --enableGitInfo --environment nonprod
5052

5153
serve: module-check ## Boot the development server.
52-
hugo server --buildFuture
54+
hugo server --buildFuture --environment development
5355

5456
docker-image:
5557
@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
7072
--build-arg HUGO_VERSION=$(HUGO_VERSION)
7173

7274
container-build: module-check
73-
$(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify"
75+
$(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development"
7476

7577
container-serve: module-check ## Boot the development server using container. Run `make container-image` before this.
76-
$(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
78+
$(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
7779

7880
test-examples:
7981
scripts/test_examples.sh install
@@ -88,7 +90,7 @@ docker-internal-linkcheck:
8890
$(MAKE) container-internal-linkcheck
8991

9092
container-internal-linkcheck: link-checker-image-pull
91-
$(CONTAINER_RUN) $(CONTAINER_IMAGE) hugo --config config.toml,linkcheck-config.toml --buildFuture
93+
$(CONTAINER_RUN) $(CONTAINER_IMAGE) hugo --config config.toml,linkcheck-config.toml --buildFuture --environment test
9294
$(CONTAINER_ENGINE) run --mount type=bind,source=$(CURDIR),target=/test --rm wjdp/htmltest htmltest
9395

9496
clean-api-reference: ## Clean all directories in API reference directory, preserve _index.md

layouts/_default/baseof.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<!doctype html>
22
<html lang="{{ .Site.Language.Lang }}" class="{{.Params.class}} no-js">
3-
<head>
3+
{{- if eq hugo.Environment "preview" -}}
4+
<!-- deploy preview -->
5+
{{- end -}}
6+
<head {{- if hugo.IsProduction -}}class="live-site"{{- end -}}>
47
{{ partial "head.html" . }}
58
</head>
69
<body class="td-{{ .Kind }}{{- if ne (lower .Params.cid) "" -}}{{- printf " cid-%s" (lower .Params.cid) -}}{{- end -}}">

layouts/index.headers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if eq (getenv "HUGO_ENV") "production" }}
1+
{{- if eq hugo.Environment "production" }}
22
{{- $cssFilesFromConfig := site.Params.pushAssets.css -}}
33
{{- $jsFilesFromConfig := site.Params.pushAssets.js -}}
44
{{- $pages := site.RegularPages -}}

layouts/partials/head.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{{- $isBlogPost := eq .Section "blog" }}
22
{{- $ogType := cond (.IsHome) "website" "article" }}
3+
<!-- per-page robot indexing controls -->
4+
{{- if hugo.IsProduction -}}
5+
<meta name="ROBOTS" content="INDEX, FOLLOW">
6+
{{- else -}}
7+
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
8+
{{- end -}}
39
<!-- Global site tag (gtag.js) - Google Analytics -->
410
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-36037335-10"></script>
511
<script>
@@ -19,11 +25,6 @@
1925
<meta charset="utf-8">
2026
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
2127
{{ hugo.Generator }}
22-
{{ if eq (getenv "HUGO_ENV") "production" }}
23-
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
24-
{{ else }}
25-
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
26-
{{ end }}
2728
{{ range .AlternativeOutputFormats -}}
2829
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
2930
{{ end -}}
@@ -33,7 +34,7 @@
3334
{{- template "_internal/google_news.html" . -}}
3435
{{- template "_internal/schema.html" . -}}
3536
{{- template "_internal/twitter_cards.html" . -}}
36-
{{ if eq (getenv "HUGO_ENV") "production" }}
37+
{{- if hugo.IsProduction -}}
3738
{{ template "_internal/google_analytics_async.html" . }}
3839
{{ end }}
3940
{{ partialCached "head-css.html" . "asdf" }}

netlify.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@ HUGO_ENABLEGITINFO = "true"
2020
command = "git submodule update --init --recursive --depth 1 && make deploy-preview"
2121

2222
[context.branch-deploy]
23-
command = "git submodule update --init --recursive --depth 1 && make deploy-preview"
23+
command = "git submodule update --init --recursive --depth 1 && make non-production-build"
2424

25-
[context.master]
26-
# This context is triggered by the `master` branch and allows search indexing
25+
[context.main]
26+
# This context is triggered by the `main` branch and allows search indexing
2727
# DO NOT REMOVE THIS (contact @kubernetes/sig-docs-leads)
2828
publish = "public"
2929
command = "git submodule update --init --recursive --depth 1 && make production-build"
30-
31-
# adding in headers to prevent clickjacking
32-
[[headers]]
33-
for = "/*"
34-
[headers.values]
35-
X-Frame-Options = "DENY"
36-
X-XSS-Protection = "1; mode=block"

0 commit comments

Comments
 (0)