theme: nicer escaping in <head>

This commit is contained in:
Sören Weber 2022-07-07 21:42:45 +02:00
parent ab5e73a97e
commit a74ec4d6f8
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
3 changed files with 14 additions and 10 deletions

View file

@ -1,14 +1,14 @@
{{- $assetBusting := not .Site.Params.disableAssetsBusting }}
{{- if (fileExists "/static/images/favicon.svg") }}
<link rel="icon" href="{{ "images/favicon.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/svg+xml">
<link href="{{ "images/favicon.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml">
{{- else if (fileExists "/static/images/favicon.png") }}
<link rel="icon" href="{{ "images/favicon.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/png">
<link href="{{ "images/favicon.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/png">
{{- else if (fileExists "/static/images/favicon.ico") }}
<link rel="icon" href="{{ "images/favicon.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/x-icon">
<link href="{{ "images/favicon.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/x-icon">
{{- else if (fileExists "/static/images/logo.svg") }}
<link rel="icon" href="{{ "images/logo.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/svg+xml">
<link href="{{ "images/logo.svg" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/svg+xml">
{{- else if (fileExists "/static/images/logo.png") }}
<link rel="icon" href="{{ "images/logo.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/png">
<link href="{{ "images/logo.png" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/png">
{{- else if (fileExists "/static/images/logo.ico") }}
<link rel="icon" href="{{ "images/logo.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" type="image/x-icon">
<link href="{{ "images/logo.ico" | relURL }}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="icon" type="image/x-icon">
{{- end }}

View file

@ -2,20 +2,21 @@
<html lang="{{ .Page.Language | default "en" }}">
<head>
{{- partial "meta.html" . }}
{{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }}
<title>{{ if and .Title (not (eq .Title .Site.Title)) }}{{ .Title }} {{ default "::" .Site.Params.titleSeparator }} {{ end}}{{ .Site.Title }}</title>
{{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }}
{{- else }}
{{- range .AlternativeOutputFormats }}
{{- if ne .Name "JSON" }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | relURL }}" title="{{ $.Site.Title | safeHTML }}" />
{{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($.Site.Title | htmlEscape)) | safeHTML }}
{{- end }}
{{- end }}
{{- end }}
{{- if and (ne .Site.Params.disableSeoHiddenPages true) (ne .Site.Params.disableSearchHiddenPages true) }}
{{- range .AlternativeOutputFormats }}
{{- if eq .Name "JSON" }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | relURL }}" title="{{ $.Site.Title | safeHTML }}" />
{{ (printf $link (.Permalink | relURL) .Rel .MediaType.Type ($.Site.Title | htmlEscape)) | safeHTML }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -2,10 +2,13 @@
<meta charset="utf-8">
{{- $c:=""}}{{/* to avoid that user swiping to the left leaves a gap on the right side, we set minimum-scale, even if not advised to */}}
<meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, minimum-scale=1.0">
{{ hugo.Generator }}
{{- $gen := hugo.Generator }}
{{- $gen = replaceRE "\\s*/>$" ">" $gen }}
{{ $gen | safeHTML }}
{{- $ver := partial "version.html" }}
{{- $ver = replaceRE "\\s*(\\S*)" "${1}" $ver }}
<meta name="generator" content="Relearn {{ $ver }}">
{{- $ver := printf "<meta name=\"generator\" content=\"%s %s\">" "Relearn" $ver }}
{{ $ver | safeHTML }}
{{- partial "page-meta.hugo" . }}
{{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }}
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">