Template: Add robots meta-tag, set noindex on staging
All checks were successful
/ build (push) Successful in 13s

Stolen from https://github.com/dereckcurry/hugo-robots-meta-tags
This commit is contained in:
jtbx 2024-01-22 22:33:14 +01:00
parent 20ab8017a1
commit 765b727cc7
4 changed files with 44 additions and 1 deletions

View file

@ -35,6 +35,8 @@ jobs:
if: github.ref_name != 'main' if: github.ref_name != 'main'
run: | 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#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 - name: Build website
run: | run: |
./fetch-calendar.sh ./fetch-calendar.sh

View file

@ -63,3 +63,8 @@ enableGitInfo = true
url = "https://wiki.ccchh.net/verein:offizielles:foemi-formular" url = "https://wiki.ccchh.net/verein:offizielles:foemi-formular"
[menu.footer.params] [menu.footer.params]
rel = "external" rel = "external"
[params.robots]
index = true
follow = true

View file

@ -3,6 +3,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8"> <meta charset="utf-8">
{{- partial "robots.html" . -}}
{{- with resources.GetRemote "https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" }} {{- with resources.GetRemote "https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" }}
<link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous"> <link rel="stylesheet" href="{{ .RelPermalink }}" crossorigin="anonymous">
{{ end }} {{ end }}
@ -17,7 +18,7 @@
{{- end }} {{- end }}
{{- end }} {{- end }}
{{ range .AlternativeOutputFormats -}} {{- range .AlternativeOutputFormats -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }} {{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .RelPermalink $.Site.Title | safeHTML }}
{{- end }} {{- end }}

View file

@ -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) }}
<meta name="robots" content="index, follow" />
{{- else if and (eq $robotsIndex true) (eq $robotsFollow false) }}
<meta name="robots" content="index, nofollow" />
{{- else if and (eq $robotsIndex false) (eq $robotsFollow true) }}
<meta name="robots" content="noindex, follow" />
{{- else if and (eq $robotsIndex false) (eq $robotsFollow false) }}
<meta name="robots" content="noindex, nofollow" />
{{- end -}}
{{- end -}}