trwnh.com/unified.test.hugo/layouts/partials/seo.html

176 lines
6.4 KiB
HTML
Raw Permalink Normal View History

2024-10-18 07:33:33 +00:00
{{- $fallbackTitle := "" }}
{{- if eq .Section "responses" }}
{{ range .Params.inReplyTo }}
{{- if . }}
{{- $fallbackTitle = printf "in response to %s" (or .name .url) }}
{{- end }}
{{- end }}
{{- else if eq .Section "wiki" }}
2024-10-05 06:27:07 +00:00
{{- $firstH1 := partial "firstH1.html" . }}
2024-10-18 07:33:33 +00:00
{{- $fallbackTitle = or $firstH1 $.File.ContentBaseName }}
{{- end }}
{{- $title := or .Title $fallbackTitle }}
{{- $fullTitle := print .Site.Title " | " $title}}
2024-10-05 06:27:07 +00:00
{{- $cover := ($.Resources.ByType "image").GetMatch "{*opengraph*}" -}}
{{ $icon := resources.GetMatch (default "" .Site.Params.icon) -}}
{{/*=== title ===*/}}
{{ "<!-- text -->" | safeHTML }}
{{- with .Site.Title }}
<meta name="application-name" property="og:site_name" content="{{ . }}" />
{{- end -}}
{{- if .IsHome}}
{{- with or .Params.name .Site.Title }}
<title>{{ . }}</title>
<meta property="og:title" name="twitter:title" itemprop="name" content="{{ . }}" />
{{- end }}
{{- else }}
<title>{{ or .Params.name $fullTitle }}</title>
2024-10-05 06:27:07 +00:00
<meta property="og:title" name="twitter:title" itemprop="name" content="{{ or .Params.name $title }}" />
{{- end -}}
{{/*=== description ===*/}}
2024-10-18 07:33:33 +00:00
{{- with or .Description .Params.summary .Site.Params.description (plainify (.Content | safeHTML) | strings.Truncate 140) }}
2024-10-05 06:27:07 +00:00
<meta name="description" itemprop="description" property="og:description" content="{{ . }}" />
<meta name="twitter:description" content="{{ . }}" />
{{- end }}
{{ "<!-- url -->" | safeHTML }}
{{- with .Permalink | absURL}}
<base href="{{ . }}" />
<link rel="canonical" href="{{ or $.Params.canonical . }}" />
<meta name="url" property="og:url" itemprop="url" content="{{ . }}" />
<meta name="twitter:url" content="{{ . }}" />
{{- end -}}
{{/*=== image ===*/}}
{{- $staticIcon := "icon.png" | absURL -}}
{{- with or $cover $icon }}
{{ "<!-- image -->" | safeHTML }}
<meta property="og:image" itemprop="image" content="{{ .Permalink | absURL }}" />
{{- with .Width }}
<meta property="og:image:width" content="{{ . }}" />
{{- end }}
{{- with .Height }}
<meta property="og:image:height" content="{{ . }}" />
{{- end }}
<meta name="twitter:image" content="{{ .Permalink | absURL }}" />
<meta name="twitter:image:src" content="{{ .Permalink | absURL }}" />
{{- else }}
{{ "<!-- image -->" | safeHTML }}
<meta property="og:image" itemprop="image" content="{{ $staticIcon }}" />
<meta name="twitter:image" content="{{ $staticIcon }}" />
<meta name="twitter:image:src" content="{{ $staticIcon }}" />
{{- end -}}
{{/*=== extra params? ===*/}}
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }}
{{- with .Params.videos }}{{- range . }}
<meta property="og:video" content="{{ . | absURL }}" />
{{ end }}{{ end -}}
2024-10-05 06:27:07 +00:00
{{/*=== article ===*/}}
{{- with or .Params.author .Site.Params.author }}
2024-10-05 06:27:07 +00:00
{{ "<!-- author -->" | safeHTML }}
<meta name="author" property="article:author" content="{{ .name }}" />
2024-10-05 06:27:07 +00:00
{{- end }}
<meta property="article:publisher" content="{{ .Site.BaseURL }}" />
2024-10-18 07:33:33 +00:00
{{- if or .Date .Lastmod }}
2024-10-05 06:27:07 +00:00
{{ "<!-- time -->" | safeHTML }}
2024-10-18 07:33:33 +00:00
{{- end }}
2024-10-05 06:27:07 +00:00
{{ with .Date -}}
<meta property="article:published_time" itemprop="datePublished" content={{ .Format "2006-01-02T03:04:05Z" | safeHTML }} />
{{ end -}}
{{ with .Lastmod -}}
<meta property="article:modified_time" itemprop="dateModified" content={{ .Format "2006-01-02T03:04:05Z" | safeHTML }} />
{{ end -}}
{{/*=== section and keywords ===*/}}
{{- with.Params.category -}}
{{- "<!-- keywords -->" | safeHTML -}}
2024-10-05 06:27:07 +00:00
<meta property="article:section" content="{{ . }}" />
{{- end -}}
{{- with .Params.tags -}}
<meta property="article:tag" itemprop="keywords" name="keywords" content='{{ delimit . ", "}}' />
2024-10-05 06:27:07 +00:00
{{- end -}}
{{/* if it has a date, it's probably an article */}}
2024-10-05 06:27:07 +00:00
{{- if isset .Params "date" }}
{{- "<!-- article metadata -->" | safeHTML }}
2024-10-05 06:27:07 +00:00
<meta property="og:type" content="article" />
<meta itemprop="wordCount" content="{{ .WordCount }}" />
<script defer type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"headline": {{ $title }},
"author": {
"@type": "Person",
"name": {{ or .Params.author.name .Site.Params.author.name }},
"url": {{ or .Params.author.url .Site.Params.author.url .Site.BaseURL }}
},
"datePublished": {{ .Date.UTC.Format "2006-01-02T03:04:05Z" }},
"description": {{ (or .Description .Summary) | plainify }},
"wordCount": {{ .WordCount }},
"mainEntityOfPage": {{.Permalink}},
"dateModified": "{{ .Lastmod.UTC.Format "2006-01-02T03:04:05Z" }}",
{{ with or $cover $icon }}
"image": {
"@type": "ImageObject",
"url": {{ .Permalink | absURL }}
},{{ end }}
"publisher": {
"@type": "WebSite",
"name": {{ .Site.Title }},
"url": {{ .Site.BaseURL }},
2024-10-05 06:27:07 +00:00
"image": {
"@type": "ImageObject",
"url": {{with $icon}}{{.Permalink}}{{else}}{{$staticIcon}}{{end}}
2024-10-05 06:27:07 +00:00
}
}
}
2024-10-05 06:27:07 +00:00
</script>
{{- else }}
{{- /* otherwise if it doesn't have a date it's probably just a webpage */}}
{{- "<!-- webpage metadata -->" | safeHTML }}
2024-10-05 06:27:07 +00:00
<meta property="og:type" content="website" />
<script defer type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebPage",
"name": {{ .Title }},
"url": {{ .Permalink }},
"description": {{ (or .Description .Summary) | plainify }},
"image": {
"@type": "ImageObject",
"url": {{with $icon}}{{.Permalink}}{{else}}{{$staticIcon}}{{end}}
}
}
</script>
{{- end -}}
{{/* auxiliary info */}}
{{ "<!-- site presentation -->" | safeHTML }}
{{ with $icon }}
<link rel="shortcut icon" href='{{ .Permalink }}' sizes="{{.Width}}x{{.Height}}" />
{{- else -}}
<link rel="shortcut icon" href='{{ $staticIcon }}' sizes="512x512" />
{{- end }}
<meta name="theme-color" content="#001a33" />{{/* TODO: make this a variable in site config */}}
<meta name="msapplication-TileColor" content="#001a33" />{{/* TODO: make this a variable in site config */}}
2024-10-05 06:27:07 +00:00
{{ with .OutputFormats.Get "RSS" -}}
<link rel="feed alternate" type="application/rss+xml" title="{{ $fullTitle }}" href="{{ .Permalink }}" />
{{- end }}
2024-10-18 07:33:33 +00:00
{{- with .OutputFormats.Get "Atom" -}}
<link rel="feed alternate" type="application/atom+xml" title="{{ $fullTitle }}" href="{{ .Permalink }}" />
{{- end }}
2024-10-18 07:33:33 +00:00
{{- with .OutputFormats.Get "Sitemap" -}}
<link rel="sitemap" type="application/xml" title="Sitemap" href="{{ .Permalink }}" />
2024-10-05 06:27:07 +00:00
{{- end -}}
2024-10-18 07:33:33 +00:00
{{- /* TODO: more output formats? or possibly loop/iterate over all output formats? (probably not, don't want to link to lunr.json do we?) */ -}}
{{- /* robots */ -}}
2024-10-05 06:27:07 +00:00
{{ "<!-- robots -->" | safeHTML }}
<meta name="robots" content="index,follow" />
<meta name="googlebot" content="index,follow" />