From 765b727cc71e05b8605b794e9abee90e3fbe0cd6 Mon Sep 17 00:00:00 2001 From: jtbx Date: Mon, 22 Jan 2024 22:33:14 +0100 Subject: [PATCH] Template: Add robots meta-tag, set noindex on staging Stolen from https://github.com/dereckcurry/hugo-robots-meta-tags --- .forgejo/workflows/deploy.yaml | 2 ++ hugo.toml | 5 ++++ themes/ccchh/layouts/partials/head.html | 3 +- themes/ccchh/layouts/partials/robots.html | 35 +++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 themes/ccchh/layouts/partials/robots.html diff --git a/.forgejo/workflows/deploy.yaml b/.forgejo/workflows/deploy.yaml index 97dde69..af22d05 100644 --- a/.forgejo/workflows/deploy.yaml +++ b/.forgejo/workflows/deploy.yaml @@ -35,6 +35,8 @@ jobs: if: github.ref_name != 'main' run: | sed -i "s#baseURL = 'https://hamburg.ccc.de/'#baseURL = 'https://staging.hamburg.ccc.de/pr${{ github.event.pull_request.number }}/'#" hugo.toml + sed -i "s#index = true#index = false#" hugo.toml + sed -i "s#follow = true#follow = false#" hugo.toml - name: Build website run: | ./fetch-calendar.sh diff --git a/hugo.toml b/hugo.toml index 948664d..251f27d 100644 --- a/hugo.toml +++ b/hugo.toml @@ -63,3 +63,8 @@ enableGitInfo = true url = "https://wiki.ccchh.net/verein:offizielles:foemi-formular" [menu.footer.params] rel = "external" + + +[params.robots] + index = true + follow = true diff --git a/themes/ccchh/layouts/partials/head.html b/themes/ccchh/layouts/partials/head.html index eeb62df..7b8744b 100644 --- a/themes/ccchh/layouts/partials/head.html +++ b/themes/ccchh/layouts/partials/head.html @@ -3,6 +3,7 @@ + {{- partial "robots.html" . -}} {{- with resources.GetRemote "https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" }} {{ end }} @@ -17,7 +18,7 @@ {{- end }} {{- end }} - {{ range .AlternativeOutputFormats -}} + {{- range .AlternativeOutputFormats -}} {{ printf `` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }} {{- end }} diff --git a/themes/ccchh/layouts/partials/robots.html b/themes/ccchh/layouts/partials/robots.html new file mode 100644 index 0000000..818e591 --- /dev/null +++ b/themes/ccchh/layouts/partials/robots.html @@ -0,0 +1,35 @@ +{{ $robotsGenerate := false -}} +{{- if or (isset $.Params.robots "index") (isset $.Params.robots "follow") }} +{{- $robotsGenerate = true -}} +{{- else if or (isset $.Site.Params.robots "index") (isset $.Site.Params.robots "follow") -}} +{{- $robotsGenerate = true -}} +{{- end -}} +{{- if eq $robotsGenerate true -}} +{{- $robotsIndex := true -}} +{{- $robotsFollow := true -}} +{{- if isset $.Site.Params "robots" -}} +{{- if isset $.Site.Params.robots "index" -}} +{{- $robotsIndex = $.Site.Params.robots.index -}} +{{- end -}} +{{- if isset $.Site.Params.robots "follow" -}} +{{- $robotsFollow = $.Site.Params.robots.follow -}} +{{- end -}} +{{- end -}} +{{- if isset $.Params "robots" -}} +{{- if isset $.Params.robots "index" -}} +{{- $robotsIndex = $.Params.robots.index -}} +{{- end -}} +{{- if isset $.Params.robots "follow" -}} +{{- $robotsFollow = $.Params.robots.follow -}} +{{- end -}} +{{- end -}} +{{- if and (eq $robotsIndex true) (eq $robotsFollow true) }} + +{{- else if and (eq $robotsIndex true) (eq $robotsFollow false) }} + +{{- else if and (eq $robotsIndex false) (eq $robotsFollow true) }} + +{{- else if and (eq $robotsIndex false) (eq $robotsFollow false) }} + +{{- end -}} +{{- end -}}