refactor: unify title and description handling in meta files (#329)

This commit is contained in:
Robert Kaussow 2022-02-07 10:57:43 +01:00 committed by GitHub
parent d94859e4ae
commit d2668b43f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 240 additions and 105 deletions

View file

@ -4,8 +4,8 @@
{
"id": {{ $index }},
"href": "{{ $page.RelPermalink }}",
"title": {{ (partial "title" $page) | jsonify }},
"parent": {{ with $page.Parent }}{{ (partial "title" .) | jsonify }}{{ else }}""{{ end }},
"title": {{ (partial "utils/title" $page) | jsonify }},
"parent": {{ with $page.Parent }}{{ (partial "utils/title" .) | jsonify }}{{ else }}""{{ end }},
"content": {{ $page.Plain | jsonify }}
}
{{ end }}

View file

@ -1,4 +1,9 @@
---
description: >
Geekdoc is a simple Hugo theme for documentations. It is intentionally designed as a fast and lean theme
and may not fit the requirements of complex projects. If a more feature-complete theme is required
there are a lot of good alternatives out there.
geekdocToC: 3
geekdocTagsToMenu: true

View file

@ -1,6 +1,5 @@
---
title: Welcome to the documentation
description: Geekdoc is a simple Hugo theme for documentations. It is intentionally designed as a fast and lean theme and may not fit the requirements of complex projects. If a more feature-complete theme is required there are a lot of good alternatives out there.
geekdocNav: false
geekdocAlign: center
geekdocAnchor: false

View file

@ -3,16 +3,17 @@
<head>
{{ partial "head/meta" . }}
<title>
{{ if not (eq .Kind "home") }}
{{ partial "title" . }}{{ printf " | " }}
{{ end }}{{ .Site.Title }}
{{- if eq .Kind "home" -}}
{{ .Site.Title }}
{{- else -}}
{{ printf "%s | %s" (partial "utils/title" .) .Site.Title }}
{{- end -}}
</title>
{{ partial "head/favicons" . }}
{{ partial "head/rel-me" . }}
{{ partial "head/microformats" . }}
{{ partial "head/others" . }}
{{ partial "head/schema" . }}
{{ partial "head/custom" . }}
</head>

View file

@ -5,7 +5,7 @@
<article
class="gdoc-markdown gdoc-markdown__align--{{ default "left" (.Page.Params.GeekdocAlign | lower) }}"
>
<h1>{{ partial "title" . }}</h1>
{{ partial "content" . }}
<h1>{{ partial "utils/title" . }}</h1>
{{ partial "utils/content" . }}
</article>
{{ end }}

View file

@ -5,7 +5,7 @@
<article
class="gdoc-markdown gdoc-markdown__align--{{ default "left" (.Page.Params.GeekdocAlign | lower) }}"
>
<h1>{{ partial "title" . }}</h1>
{{ partial "content" . }}
<h1>{{ partial "utils/title" . }}</h1>
{{ partial "utils/content" . }}
</article>
{{ end }}

View file

@ -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 -}}

View file

@ -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 }}

View file

@ -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" . }}

View file

@ -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 }}

View file

@ -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>

View file

@ -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">

View file

@ -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 }}

View 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 }}

View 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 }}

View 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 }}

View file

@ -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>

View 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 }}

View 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 }}

View file

@ -2,7 +2,9 @@
{{ range .Paginator.Pages }}
<article class="gdoc-markdown gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
<h1 class="gdoc-post__title">
<a href="{{ .RelPermalink }}">{{ partial "utils/title" . }}</a>
</h1>
</header>
<section>
{{ .Summary }}

View file

@ -1,13 +1,13 @@
{{ define "main" }}
<article class="gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title">{{ .Title }}</h1>
<h1 class="gdoc-post__title">{{ partial "utils/title" . }}</h1>
<div class="flex flex-wrap align-center gdoc-post__meta gdoc-post__meta--head">
{{ partial "posts/metadata.html" . }}
</div>
</header>
<section class="gdoc-markdown">
{{ partial "content" . }}
{{ partial "utils/content" . }}
</section>
</article>
{{ end }}

View file

@ -17,13 +17,15 @@
{{ if or .Content .Params.GeekdocFlatSection }}
<span>
<a href="{{ .RelPermalink }}" class="gdoc-toc__entry">
{{ partial "title" . }}{{ with .Params.GeekdocDescription }}:{{ end }}
{{ partial "utils/title" . }}{{ with .Params.GeekdocDescription }}:{{ end }}
</a>
{{ with .Params.GeekdocDescription }}{{ . }}{{ end }}
</span>
{{ else }}
<span>
{{ partial "title" . }}{{ with .Params.GeekdocDescription }}: {{ . }}{{ end }}
{{ partial "utils/title" . }}{{ with .Params.GeekdocDescription }}
: {{ . }}
{{ end }}
</span>
{{ end }}

View file

@ -2,7 +2,9 @@
{{ range .Paginator.Pages }}
<article class="gdoc-markdown gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
<h1 class="gdoc-post__title">
<a href="{{ .RelPermalink }}">{{ partial "utils/title" . }}</a>
</h1>
</header>
<section>
{{ .Summary }}