refactor: unify title and description handling in meta files (#329)
This commit is contained in:
parent
d94859e4ae
commit
d2668b43f6
24 changed files with 240 additions and 105 deletions
|
@ -1,4 +0,0 @@
|
|||
{{- $content := .Content -}}
|
||||
{{- $content = $content | replaceRE `<nav id="TableOfContents">\s*<ul>\s*<li>\s*<ul>` `<nav id="TableOfContents"><ul>` | replaceRE `</ul>\s*</li>\s*</ul>\s*</nav>` `</ul></nav>` | safeHTML -}}
|
||||
{{- $content = $content | replaceRE `(<table>(?:.|\n)+?</table>)` `<div class=table-wrap> ${1} </div>` | safeHTML -}}
|
||||
{{- $content -}}
|
|
@ -1,13 +1,14 @@
|
|||
<meta charset="UTF-8" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
{{ hugo.Generator }}
|
||||
|
||||
{{ $description := default (default .Site.Title .Site.Params.description) (default .Summary .Description) }}
|
||||
{{ $keywords := default .Site.Params.Keywords .Keywords }}
|
||||
|
||||
{{ with $description }}
|
||||
<meta name="description" content="{{ . }}" />
|
||||
{{ end }}
|
||||
{{ with $keywords }}
|
||||
{{- with partial "utils/description" . }}
|
||||
<meta name="description" content="{{ trim (. | plainify) "\n" }}" />
|
||||
{{- end }}
|
||||
{{- with $keywords }}
|
||||
<meta name="keywords" content="{{ delimit . "," }}" />
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
{{ template "_internal/opengraph.html" . }}
|
||||
{{ template "_internal/twitter_cards.html" . }}
|
||||
{{ partial "microformats/opengraph.html" . }}
|
||||
{{ partial "microformats/twitter_cards.html" . }}
|
||||
{{ partial "microformats/schema" . }}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
{{ if .IsHome -}}
|
||||
{{ $thumbnail := default (default "brand.svg" .Site.Params.logo) (index (default slice .Site.Params.images) 0) | absURL }}<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "WebSite",
|
||||
"name": "{{ .Site.Title }}",
|
||||
"url": "{{ .Site.BaseURL }}",
|
||||
{{- with .Site.Params.description }}
|
||||
"description": "{{ . }}",
|
||||
{{- end }}
|
||||
"thumbnailUrl": "{{ $thumbnail }}"
|
||||
{{- with .Site.Params.GeekdocContentLicense }},
|
||||
"license": "{{ .name }}"
|
||||
{{- end }}
|
||||
}
|
||||
</script>
|
||||
{{ else if .IsPage }}
|
||||
{{ $description := default .Site.Params.description (default .Description .Summary) }}
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"articleSection": "{{ .Section }}",
|
||||
"name": "{{ .Title | safeJS }}",
|
||||
"headline": "{{ .Title | safeJS }}",
|
||||
"alternativeHeadline": "{{ .Params.lead }}",
|
||||
{{- with $description }}
|
||||
"description": "{{ . }}",
|
||||
{{- end }}
|
||||
"inLanguage": {{ .Site.Language.Lang }},
|
||||
"isFamilyFriendly": "true",
|
||||
"mainEntityOfPage": {
|
||||
"@type": "WebPage",
|
||||
"@id": "{{ .Permalink }}"
|
||||
},
|
||||
"copyrightHolder" : "{{ .Site.Title }}",
|
||||
"copyrightYear" : "{{ .Date.Format "2006" }}",
|
||||
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"publisher":{
|
||||
"@type":"Organization",
|
||||
"name": {{ .Site.Title }},
|
||||
"url": {{ .Site.BaseURL }},
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": "{{ (default "brand.svg" .Site.Params.logo) | absURL }}",
|
||||
"width":"32",
|
||||
"height":"32"
|
||||
}
|
||||
},
|
||||
{{- with $images := $.Resources.ByType "image" }}
|
||||
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image.Permalink | absURL }}" {{ end }}],
|
||||
{{- else }}
|
||||
{{- with $images := .Params.images }}
|
||||
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image | absURL }}" {{ end }}],
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
"url" : "{{ .Permalink }}",
|
||||
"wordCount" : "{{ .WordCount }}",
|
||||
{{- with $tags := .Params.tags }}
|
||||
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
|
||||
{{- end }}
|
||||
}
|
||||
</script>
|
||||
{{ end }}
|
|
@ -52,9 +52,9 @@
|
|||
{{ else }}
|
||||
{{ relref $current .ref }}
|
||||
{{ end }}"
|
||||
class="gdoc-nav__entry {{ if not .external }}
|
||||
{{ if $isCurrent }}is-active{{ end }}
|
||||
{{ end }}"
|
||||
class="gdoc-nav__entry{{- if not .external }}
|
||||
{{- if $isCurrent }}{{ printf " is-active" }}{{ end }}
|
||||
{{- end }}"
|
||||
>
|
||||
{{ $name }}
|
||||
</a>
|
||||
|
|
|
@ -68,13 +68,15 @@
|
|||
<span class="flex">
|
||||
<a
|
||||
href="{{ .RelPermalink }}"
|
||||
class="gdoc-nav__entry {{ if eq $current . }}is-active{{ end }}"
|
||||
class="gdoc-nav__entry{{- if eq $current . }}
|
||||
{{- printf " is-active" }}
|
||||
{{- end }}"
|
||||
>
|
||||
{{ partial "title" . }}
|
||||
{{ partial "utils/title" . }}
|
||||
</a>
|
||||
</span>
|
||||
{{ else }}
|
||||
<span class="flex">{{ partial "title" . }}</span>
|
||||
<span class="flex">{{ partial "utils/title" . }}</span>
|
||||
{{ end }}
|
||||
{{ if $doCollapse }}
|
||||
<svg class="icon toggle gdoc_keyboard_arrow_left">
|
||||
|
|
|
@ -20,10 +20,12 @@
|
|||
{{ with $.Site.GetPage (printf "/tags/%s" $name) }}
|
||||
<li>
|
||||
<a
|
||||
class="gdoc-nav__entry {{ if eq $currentPage .RelPermalink }}is-active{{ end }}"
|
||||
class="gdoc-nav__entry{{- if eq $currentPage .RelPermalink }}
|
||||
{{- printf " is-active" }}
|
||||
{{- end }}"
|
||||
href="{{ .RelPermalink }}"
|
||||
>
|
||||
{{ .Title }}
|
||||
{{ partial "utils/title" . }}
|
||||
</a>
|
||||
</li>
|
||||
{{ end }}
|
||||
|
|
74
layouts/partials/microformats/opengraph.html
Normal file
74
layouts/partials/microformats/opengraph.html
Normal file
|
@ -0,0 +1,74 @@
|
|||
{{- if not (eq .Kind "home") }}
|
||||
<meta property="og:title" content="{{ partial "utils/title" . }}" />
|
||||
{{- end }}
|
||||
{{- with .Site.Title }}
|
||||
<meta property="og:site_name" content="{{ . }}" />
|
||||
{{- end }}
|
||||
{{- with partial "utils/description" . }}
|
||||
<meta property="og:description" content="{{ trim (. | plainify) "\n" }}" />
|
||||
{{- end }}
|
||||
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
|
||||
<meta property="og:url" content="{{ .Permalink }}" />
|
||||
|
||||
{{- with $.Params.images }}
|
||||
{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
|
||||
{{- else }}
|
||||
{{- $featured := ($.Resources.ByType "image").GetMatch "{*feature*,*cover*,*thumbnail*}" -}}
|
||||
{{- with $featured }}
|
||||
<meta property="og:image" content="{{ $featured.Permalink }}" />
|
||||
{{- else }}
|
||||
{{- with $.Site.Params.images }}
|
||||
<meta property="og:image" content="{{ index . 0 | absURL }}" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- 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 }}
|
||||
|
||||
{{- /* If it is part of a series, link to related articles */}}
|
||||
{{- if .Site.Taxonomies.series }}
|
||||
{{- $permalink := .Permalink -}}
|
||||
{{- $siteSeries := .Site.Taxonomies.series -}}
|
||||
{{- with .Params.series }}
|
||||
{{- range $name := . }}
|
||||
{{- $series := index $siteSeries ($name | urlize) }}
|
||||
{{- range $page := first 6 $series.Pages }}
|
||||
{{- if ne $page.Permalink $permalink }}
|
||||
<meta property="og:see_also" content="{{ $page.Permalink }}" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{ if .IsPage -}}
|
||||
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
|
||||
<meta property="article:section" content="{{ .Section | humanize | title }}" />
|
||||
{{- with .PublishDate }}
|
||||
<meta
|
||||
property="article:published_time"
|
||||
{{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}
|
||||
/>
|
||||
{{- end }}
|
||||
{{- with .Lastmod }}
|
||||
<meta
|
||||
property="article:modified_time"
|
||||
{{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }}
|
||||
/>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{- /* Facebook Page Admin ID for Domain Insights */}}
|
||||
{{- with .Site.Social.facebook_admin }}
|
||||
<meta property="fb:admins" content="{{ . }}" />
|
||||
{{- end }}
|
67
layouts/partials/microformats/schema.html
Normal file
67
layouts/partials/microformats/schema.html
Normal file
|
@ -0,0 +1,67 @@
|
|||
{{- if .IsHome -}}
|
||||
{{- $thumbnail := default (default "brand.svg" .Site.Params.logo) (index (default slice .Site.Params.images) 0) | absURL }}
|
||||
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "WebSite",
|
||||
"name": "{{ .Site.Title }}",
|
||||
"url": "{{ .Site.BaseURL }}",
|
||||
{{- with partial "utils/description" . }}
|
||||
"description": "{{ trim (. | plainify) "\n" }}",
|
||||
{{- end }}
|
||||
"thumbnailUrl": "{{ $thumbnail }}"
|
||||
{{- with .Site.Params.GeekdocContentLicense }},
|
||||
"license": "{{ .name }}"
|
||||
{{- end }}
|
||||
}
|
||||
</script>
|
||||
{{- else if .IsPage }}
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "TechArticle",
|
||||
"articleSection": "{{ .Section | humanize | title }}",
|
||||
"name": "{{ (partial "utils/title" .) | safeJS }}",
|
||||
"headline": "{{ (partial "utils/title" .) | safeJS }}",
|
||||
"alternativeHeadline": "{{ .Params.lead }}",
|
||||
{{- with partial "utils/description" . }}
|
||||
"description": "{{ trim (. | plainify) "\n" }}",
|
||||
{{- end }}
|
||||
"inLanguage": {{ .Site.Language.Lang }},
|
||||
"isFamilyFriendly": "true",
|
||||
"mainEntityOfPage": {
|
||||
"@type": "WebPage",
|
||||
"@id": "{{ .Permalink }}"
|
||||
},
|
||||
"copyrightHolder" : "{{ .Site.Title }}",
|
||||
"copyrightYear" : "{{ .Date.Format "2006" }}",
|
||||
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||
"publisher":{
|
||||
"@type":"Organization",
|
||||
"name": {{ .Site.Title }},
|
||||
"url": {{ .Site.BaseURL }},
|
||||
"logo": {
|
||||
"@type": "ImageObject",
|
||||
"url": "{{ (default "brand.svg" .Site.Params.logo) | absURL }}",
|
||||
"width":"32",
|
||||
"height":"32"
|
||||
}
|
||||
},
|
||||
{{- with $images := $.Resources.ByType "image" }}
|
||||
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image.Permalink | absURL }}" {{ end }}],
|
||||
{{- else }}
|
||||
{{- with $images := .Params.images }}
|
||||
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image | absURL }}" {{ end }}],
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
"url" : "{{ .Permalink }}",
|
||||
"wordCount" : "{{ .WordCount }}",
|
||||
{{- with $tags := .Params.tags }}
|
||||
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
|
||||
{{- end }}
|
||||
}
|
||||
</script>
|
||||
{{- end }}
|
28
layouts/partials/microformats/twitter_cards.html
Normal file
28
layouts/partials/microformats/twitter_cards.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{{- with $.Params.images -}}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:image" content="{{ index . 0 | absURL }}" />
|
||||
{{- else }}
|
||||
{{- $images := $.Resources.ByType "image" -}}
|
||||
{{- $featured := $images.GetMatch "*feature*" -}}
|
||||
{{- if not $featured }}
|
||||
{{- $featured = $images.GetMatch "{*cover*,*thumbnail*}" -}}
|
||||
{{- end }}
|
||||
{{- with $featured }}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:image" content="{{ $featured.Permalink }}" />
|
||||
{{- else }}
|
||||
{{- with $.Site.Params.images }}
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:image" content="{{ index . 0 | absURL }}" />
|
||||
{{- else }}
|
||||
<meta name="twitter:card" content="summary" />
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<meta name="twitter:title" content="{{ partial "utils/title" . }}" />
|
||||
{{- with partial "utils/description" . }}
|
||||
<meta name="twitter:description" content="{{ trim (. | plainify) "\n" }}" />
|
||||
{{- end }}
|
||||
{{- with .Site.Social.twitter -}}
|
||||
<meta name="twitter:site" content="@{{ . }}" />
|
||||
{{- end }}
|
|
@ -9,7 +9,7 @@
|
|||
{{ define "breadcrumb" }}
|
||||
{{ $parent := .page.Parent }}
|
||||
{{ if $parent }}
|
||||
{{ $name := (partial "title" $parent) }}
|
||||
{{ $name := (partial "utils/title" $parent) }}
|
||||
{{ $position := (sub .position 1) }}
|
||||
{{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><a itemscope itemtype='https://schema.org/WebPage' itemprop='item' itemid='%s' href='%s'><span itemprop='name'>%s</span></a><meta itemprop='position' content='%d' /></li><li> / </li>%s" $parent.RelPermalink $parent.RelPermalink $name $position .value) }}
|
||||
{{ template "breadcrumb" dict "page" $parent "value" $value "position" $position }}
|
||||
|
@ -36,7 +36,7 @@
|
|||
<svg class="icon gdoc_path hidden-mobile"><use xlink:href="#gdoc_path"></use></svg>
|
||||
<ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
|
||||
{{ $position := sub (len (split .RelPermalink "/")) 1 }}
|
||||
{{ $name := (partial "title" .) }}
|
||||
{{ $name := (partial "utils/title" .) }}
|
||||
{{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><span itemprop='name'>%s</span><meta itemprop='position' content='%d' /></li>" $name $position ) }}
|
||||
{{ template "breadcrumb" dict "page" . "value" $value "position" $position }}
|
||||
</ol>
|
||||
|
|
6
layouts/partials/utils/content.html
Normal file
6
layouts/partials/utils/content.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{ $content := .Content }}
|
||||
|
||||
{{ $content = $content | replaceRE `<nav id="TableOfContents">\s*<ul>\s*<li>\s*<ul>` `<nav id="TableOfContents"><ul>` | replaceRE `</ul>\s*</li>\s*</ul>\s*</nav>` `</ul></nav>` | safeHTML }}
|
||||
{{ $content = $content | replaceRE `(<table>(?:.|\n)+?</table>)` `<div class=table-wrap> ${1} </div>` | safeHTML }}
|
||||
|
||||
{{ return $content }}
|
13
layouts/partials/utils/description.html
Normal file
13
layouts/partials/utils/description.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
{{ $description := "" }}
|
||||
|
||||
{{ if .Description }}
|
||||
{{ $description = .Description }}
|
||||
{{ else }}
|
||||
{{ if .IsPage }}
|
||||
{{ $description = .Summary }}
|
||||
{{ else if .Site.Params.description }}
|
||||
{{ $description = .Site.Params.description }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ return $description }}
|
Loading…
Add table
Add a link
Reference in a new issue