Improve metadata and make it more robust

This commit is contained in:
a 2022-10-25 18:08:11 -05:00 committed by GitHub
parent 3fc0ddf5d1
commit 653247d765
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,98 +1,132 @@
{{ $icon := "images/icon.png" | absURL }} {{ "<!-- title -->" | safeHTML }}
<link rel="shortcut icon" href='{{ $icon }}' sizes="765x765"> <title itemprop="name">{{ .Title }} | {{ .Site.Title }}</title>
{{ if .IsPage }}{{ with .Params.tags }}<meta name="keywords" content='{{ delimit . " "}}'>{{ end }}{{ end }} <meta property="og:title" content="{{ .Title }}" />
{{ if .IsHome }}<title>{{ .Site.Title }}</title> <meta name="twitter:title" content="{{ .Title }}" />
<title itemprop="name">{{ .Site.Title }}</title> <meta name="application-name" content="{{ .Site.Title }}" />
<meta property="og:title" content="{{ .Site.Title }}" /> <meta property="og:site_name" content="{{ .Site.Title }}" />
<meta name="twitter:title" content="{{ .Site.Title }}" />
<meta itemprop="name" content="{{ .Site.Title }}" /> {{- with or .Description .Summary .Site.Params.description }}
{{ else }}<title>{{ .Title }} | {{ .Site.Title }}</title> {{ "<!-- description -->" | safeHTML }}
<title itemprop="name">{{ .Title }} | {{ .Site.Title }}</title> <meta name="description" content="{{.}}">
<meta property="og:title" content="{{ .Title }} | {{ .Site.Title }}" /> <meta itemprop="description" content="{{.}}" />
<meta name="twitter:title" content="{{ .Title }} | {{ .Site.Title }}" /> <meta property="og:description" content="{{.}}" />
<meta itemprop="name" content="{{ .Title }} | {{ .Site.Title }}" />{{ end }} <meta name="twitter:description" content="{{.}}" />
<meta name="application-name" content="{{ .Site.Title }}" /> {{ end -}}
<meta property="og:site_name" content="{{ .Site.Title }}" /> {{ "<!-- url -->" | safeHTML }}
<meta name="description" content="{{ .Summary }}"> <base href="{{ .Permalink | absURL }}">
<meta itemprop="description" content="{{ .Summary }}" /> <link rel="canonical" href="{{ .Permalink | absURL }}" itemprop="url" />
<meta property="og:description" content="{{ .Summary }}" /> <meta name="url" content="{{ .Permalink | absURL }}" />
<meta name="twitter:description" content="{{ .Summary }}" /> <meta name="twitter:url" content="{{ .Permalink | absURL }}" />
<base href="{{ .Permalink }}"> <meta property="og:url" content="{{ .Permalink | absURL }}" />
<link rel="canonical" href="{{ .Permalink }}" itemprop="url" />
<meta name="url" content="{{ .Permalink }}" /> {{- $cover := ($.Resources.ByType "image").GetMatch "{*cover*,*thumbnail*,*featured*}" -}}
<meta name="twitter:url" content="{{ .Permalink }}" /> {{ $icon := resources.GetMatch (default "" .Site.Params.icon) -}}
<meta property="og:url" content="{{ .Permalink }}" /> {{- $staticIcon := "icon.png" | absURL -}}
{{ with .Params.cover }}<meta itemprop="image" content="{{ . | absURL }}" /> {{- with or .Params.cover $cover $icon }}
<meta property="og:image" content="{{ . | absURL }}" /> {{ "<!-- image -->" | safeHTML }}
<meta name="twitter:image" content="{{ . | absURL }}" /> <meta itemprop="image" content='{{ .Permalink | absURL }}' />
<meta name="twitter:image:src" content="{{ . | absURL }}" />{{ else }} <meta property="og:image" content='{{ .Permalink | absURL }}' />
<meta itemprop="image" content='{{ $icon }}' /> {{- with .Width }}
<meta property="og:image" content='{{ $icon }}' /> <meta property="og:image:width" content='{{ . }}' />
<meta name="twitter:image" content='{{ $icon }}' /> {{- end }}
<meta name="twitter:image:src" content='{{ $icon }}' />{{ end }} {{- with .Height }}
<meta property="og:updated_time" content={{ .Lastmod.Format "2006-01-02T15:04:05Z0700" | safeHTML }} /> <meta property="og:image:height" content='{{ . }}' />
{{ if isset .Params "date" }}<meta property="og:type" content="article" /> {{- end }}
<script defer type="application/ld+json"> <meta name="twitter:image" content='{{ .Permalink | absURL }}' />
{ <meta name="twitter:image:src" content='{{ .Permalink | absURL }}' />
"@context": "http://schema.org", {{- else }}
"@type": "Article", {{ "<!-- image -->" | safeHTML }}
"headline": {{ .Title }}, <meta itemprop="image" content='{{ $staticIcon }}' />
"author": { <meta property="og:image" content='{{ $staticIcon }}' />
"@type": "Person", <meta name="twitter:image" content='{{ $staticIcon }}' />
"name": "{{ .Params.author }}" <meta name="twitter:image:src" content='{{ $staticIcon }}' />
}, {{- end -}}
"datePublished": "{{ .Date.Format "2006-01-02" }}",
"description": {{ .Summary }}, {{/*=== author ===*/}}
"wordCount": {{ .WordCount }}, {{ with or .Params.author .Site.Params.author -}}
"mainEntityOfPage": "True", {{ "<!-- author -->" | safeHTML }}
"dateModified": "{{ .Lastmod.Format "2006-01-02" }}", <meta property="article:publisher" content="{{ . }}" />
"image": { <meta property="og:article:author" content="{{ . }}" />
"@type": "imageObject", <meta property="article:author" content="{{ . }}" />
"url": "{{ with .Params.cover }}{{ . }}{{ end }}" <meta name="author" content="{{ . }}" />
}, {{- end -}}
"publisher": {
"@type": "Person", {{/*=== published and updated ===*/}}
"name": "{{ .Site.Title }}", {{ "<!-- time -->" | safeHTML }}
"logo": { {{- with .Date }}
"@type": "imageObject", <meta property="og:article:published_time" content={{ .Format "2006-01-02T15:04:05Z0700" | safeHTML }} />
"url": {{ $icon }} <meta property="article:published_time" content={{ .Format "2006-01-02T15:04:05Z0700" | safeHTML }} />
{{ end -}}
{{ with .Lastmod -}}
<meta property="og:updated_time" content={{ .Format "2006-01-02T15:04:05Z0700" | safeHTML }} />
{{ end -}}
{{/*=== section and keywords ===*/}}
{{- with.Params.category -}}
<meta name="news_keywords" content="{{ . }}" />
<meta property="article:section" content="{{ . }}" />
{{- end -}}
{{- with .Params.tags }}
<meta name="keywords" content='{{ delimit . " "}}'>
{{- end -}}
{{- if isset .Params "date" -}}
{{ "<!-- article metadata -->" | safeHTML }}
<meta property="og:type" content="article" />
<script defer type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"headline": {{ .Title }},
"author": {
"@type": "Person",
"name": "{{ or .Params.author .Site.Params.author }}"
},
"datePublished": "{{ .Date.Format "2006-01-02" }}",
"description": {{ or .Description .Summary }},
"wordCount": {{ .WordCount }},
"mainEntityOfPage": "True",
"dateModified": "{{ .Lastmod.Format "2006-01-02" }}",
"image": {
"@type": "imageObject",
"url": "{{ with or .Params.cover $cover $icon }}{{ .Permalink | absURL }}{{ end }}"
},
"publisher": {
"@type": "Person",
"name": "{{ or .Params.author .Site.Params.author .Site.Title }}",
"logo": {
"@type": "imageObject",
"url": {{with $icon}}{{.Permalink}}{{else}}{{$staticIcon}}{{end}}
}
} }
} }
}
</script> </script>
{{ else }}<meta property="og:type" content="website" /> {{- else -}}
<meta name="author" content="{{ .Params.author }}" /> {{ "<!-- webpage metadata -->" | safeHTML }}
<script defer type="application/ld+json"> <meta property="og:type" content="website" />
{ <script defer type="application/ld+json">
"@context": "http://schema.org", {
"@type": "WebSite", "@context": "http://schema.org",
"url": {{ .Permalink }}, "@type": "WebSite",
"name": "{{ .Title }}", "url": {{ .Permalink }},
"logo": {{ $icon }} "name": "{{ .Site.Title }}",
} "logo": {{with $icon}}{{.Permalink}}{{else}}{{$staticIcon}}{{end}}
</script>{{ end }} }
<meta property="article:publisher" content="{{ .Params.author }}" /> </script>
{{ with.Params.author }}<meta property="og:article:author" content="{{ . }}" /> {{- end -}}
<meta property="article:author" content="{{ . }}" />
<meta name="author" content="{{ . }}" />{{ end }} {{/* auxiliary info */}}
{{ with.Params.category }}<meta name="news_keywords" content="{{ . }}" /> {{ "<!-- site presentation -->" | safeHTML }}
<meta property="article:section" content="{{ . }}" />{{ end }} {{- with $icon }}
<meta property="og:article:published_time" content={{ .Date.Format "2006-01-02T15:04:05Z0700" | safeHTML }} /> <link rel="shortcut icon" href='{{ .Permalink }}' sizes="{{.Width}}x{{.Height}}">
<meta property="article:published_time" content={{ .Date.Format "2006-01-02T15:04:05Z0700" | safeHTML }} /> {{- else -}}
<link rel="sitemap" type="application/xml" title="Sitemap" href="{{ .Site.BaseURL }}sitemap.xml" /> <link rel="shortcut icon" href='{{ $staticIcon }}' sizes="512x512">
{{ with .OutputFormats.Get "RSS" }}<link href="{{ .Permalink }}" rel="alternate" type="application/rss+xml" title="{{ $.Site.Title }}" /> {{- end }}
<link href="{{ .Permalink }}" rel="feed" type="application/rss+xml" title="{{ $.Site.Title }}" />{{ end }} <meta name="theme-color" content="#ffffff" />
<meta name="robots" content="index,follow" /> <meta name="msapplication-TileColor" content="#ffffff" />
<meta name="googlebot" content="index,follow" /> <link rel="sitemap" type="application/xml" title="Sitemap" href="{{ .Site.BaseURL }}sitemap.xml" />
<link rel="manifest" href="{{ .Site.BaseURL }}manifest.json" /> {{ with .OutputFormats.Get "RSS" -}}
<meta name="theme-color" content="#ffffff" /> <link href="{{ .Permalink }}" rel="feed alternate" type="application/rss+xml" title="{{ $.Site.Title }}" />
<meta name="msapplication-TileColor" content="#ffffff" /> {{- end }}
<meta name="imagemode" content="force" /> <meta name="robots" content="index,follow" />
<meta name="coverage" content="Worldwide" /> <meta name="googlebot" content="index,follow" />
<meta name="distribution" content="Global" />
<meta name="HandheldFriendly" content="True" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="apple-mobile-web-app-title" content="{{ .Site.Title }}" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-touch-fullscreen" content="yes" />