ccchh-website/themes/ccchh/layouts/partials/robots.html
jtbx 63d3f4459d
All checks were successful
/ build (pull_request) Successful in 40s
/ cleanup-staging (pull_request) Successful in 1s
/ build (push) Successful in 12s
Theme: Fix robots partial "isset on nil" warning
As not all pages have the robots param defined, we got a warning:
WARN  calling IsSet with unsupported type "invalid" (<nil>) will always return false.
This is solved by adding an additional "isset" check.
2024-04-20 18:14:41 +02:00

36 lines
1.5 KiB
HTML

{{ $robotsGenerate := false -}}
{{- if and (isset $.Params "robots") (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 -}}