abdullahtarawneh.com/layouts/partials/site/seo.html
2024-06-05 12:42:53 -05:00

159 lines
5.5 KiB
HTML

{{- $cover := ($.Resources.ByType "image").GetMatch "{*cover*,*thumbnail*,*featured*}" -}}
{{ $icon := resources.GetMatch (default "" .Site.Params.icon) -}}
{{- $staticIcon := "icon.png" | absURL -}}
{{- $author := index ($.GetTerms "authors") 0 -}}
{{/*=== 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 (print .Title " - " .Site.Title) }}</title>
<meta property="og:title" name="twitter:title" itemprop="name" content="{{ or .Params.name .Title }}" />
{{- end -}}
{{/*=== description ===*/}}
{{- with or .Description .Summary .Site.Params.description }}
<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 ===*/}}
{{- 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 -}}
{{/*=== section and keywords ===*/}}
{{ "<!-- keywords -->" | safeHTML }}
{{- with .Params.categories }}
{{- range . }}
<meta property="article:section" content="{{ . }}" />
{{- end }}
{{- end -}}
{{- with .Params.tags }}
<meta property="article:tag" itemprop="keywords" name="keywords" content='{{ delimit . " "}}' />
{{- end -}}
{{ if .Date }}
{{ "<!-- article metadata -->" | safeHTML }}
<meta property="og:type" content="article" />
{{ with $author -}}
<meta name="author" property="article:author" content="{{ .Title }}" />
{{- end }}
<meta property="article:publisher" content="{{ .Site.BaseURL }}" />
{{ with .Date -}}
<meta property="article:published_time" itemprop="datePublished" content={{ .Format "2006-01-02T15:04:05Z" | safeHTML }} />
{{ end -}}
{{ with .Lastmod -}}
<meta property="article:modified_time" itemprop="dateModified" content={{ .Format "2006-01-02T15:04:05Z" | safeHTML }} />
{{ end -}}
<meta itemprop="wordCount" content="{{ .WordCount }}" />
<script defer type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"headline": {{ .Title }},
{{- with $author }}
"author": {
"@type": "Person",
"name": {{ .Title }},
"url": {{ .Permalink }},
{{- with .Resources.GetMatch "avatar" }}
"image": {
"@type": "ImageObject",
"url": {{ .Permalink }}
}
{{- end }}
},
{{- end }}
"datePublished": {{ .Date.UTC.Format "2006-01-02T15:04:05Z" }},
"description": {{ (or .Description .Summary) | plainify }},
"wordCount": {{ .WordCount }},
"mainEntityOfPage": {{.Permalink}},
"dateModified": "{{ .Lastmod.UTC.Format "2006-01-02T15:04:05Z" }}",
"image": {
"@type": "ImageObject",
"url": {{ with or $cover $icon }}{{ .Permalink | absURL }}{{ end }}
},
"publisher": {
"@type": "WebSite",
"name": {{ .Site.Title }},
"url": {{ .Site.BaseURL }},
"image": {
"@type": "ImageObject",
"url": {{with $icon}}{{.Permalink}}{{else}}{{$staticIcon}}{{end}}
}
}
}
</script>
{{- else }}
{{ "<!-- webpage metadata -->" | safeHTML }}
<meta property="og:type" content="website" />
<meta name="author" content="{{ .Site.Params.author.name }}" />
<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 apple-touch-icon image_src" href='{{ .Permalink }}' sizes="{{.Width}}x{{.Height}}" />
{{- else -}}
<link rel="shortcut icon apple-touch-icon image_src" href='{{ $staticIcon }}' />
{{- end }}
<meta name="theme-color" content="#CCE6FF" />
<meta name="msapplication-TileColor" content="#CCE6FF" />
<link rel="sitemap" type="application/xml" title="Sitemap" href="{{ .Site.BaseURL }}sitemap.xml" />
{{ with .OutputFormats.Get "RSS" -}}
<link href="{{ .Permalink }}" rel="feed alternate" type="application/rss+xml" title="{{ $.Site.Title }}" />
{{- end -}}
{{/* robots */}}
{{- "<!-- robots -->" | safeHTML }}
<meta name="robots" content="index,follow" />
<meta name="googlebot" content="index,follow" />