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

This commit is contained in:
Robert Kaussow 2022-02-05 20:02:17 +01:00 committed by GitHub
parent b83812d09f
commit 91f44eb3a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 127 additions and 126 deletions

View File

@ -8,9 +8,11 @@
<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" . }}

View File

@ -50,9 +50,7 @@
{{- end }}
<published>{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</published>
<updated>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
{{ $desc := .Description | default "" }}
{{ $description := (cond (eq "" $desc) "" (printf "<blockquote>%s</blockquote>" ($desc | $.Page.RenderString))) }}
{{ printf `<content type="html"><![CDATA[%s%s]]></content>` $description .Content | safeHTML }}
{{ printf `<content type="html"><![CDATA[%s]]></content>` .Content | safeHTML }}
{{ with .Site.Taxonomies }}
{{ range $taxo,$_ := . }} <!-- Defaults taxos: "tags", "categories" -->
{{ with $page.Param $taxo }}

View File

@ -9,12 +9,12 @@
<article class="gblog-post">
<header class="gblog-post__header">
<h1 class="gblog-post__title">
<a href="{{ .RelPermalink }}">{{ partial "title" . }}</a>
<a href="{{ .RelPermalink }}">{{ partial "utils/title" . }}</a>
</h1>
</header>
<section class="gblog-markdown">
{{ .Summary }}
{{ partial "utils/description" . }}
</section>
<div class="gblog-post__readmore">
{{ if .Truncated }}

View File

@ -7,7 +7,10 @@
<picture>
{{ $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) }}
<source srcset="{{ $featured.Permalink }}" />
<img src="{{ $featured.Permalink }}" alt="{{ default $.Title .Params.description }}" />
<img
src="{{ $featured.Permalink }}"
alt="{{ default (partial "utils/title" $) .Params.description }}"
/>
</picture>
{{ with $source.Params.credits }}
<span>Credits: {{ . | $.Page.RenderString | safeHTML }}</span>
@ -16,7 +19,7 @@
{{ end }}
<h1 class="gblog-post__title">{{ partial "title" . }}</h1>
<h1 class="gblog-post__title">{{ partial "utils/title" . }}</h1>
{{ if or (eq .Type (default "posts" .Site.Params.GeekblogContentSection)) (eq .Type "post") }}
<div class="flex flex-wrap align-center gblog-post__meta gblog-post__meta--head">

View File

@ -4,7 +4,7 @@
<article class="gblog-post">
<header class="gblog-post__header">
<h1 class="gblog-post__title">
<a href="{{ .RelPermalink }}">{{ partial "title" . }}</a>
<a href="{{ .RelPermalink }}">{{ partial "utils/title" . }}</a>
</h1>
</header>
@ -23,7 +23,7 @@
<span>
{{ $latet := index .Pages.ByDate 0 }}
{{ with $latet }}
<a href="{{ .RelPermalink }}">{{ partial "title" . }}</a>
<a href="{{ .RelPermalink }}">{{ partial "utils/title" . }}</a>
{{ end }}
<i>by</i>
{{ $ac := 0 }}

View File

@ -1,12 +1,11 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ $description := default (default .Site.Title .Site.Params.description) (default .Summary .Description) }}
{{ $keywords := default .Site.Params.Keywords .Keywords }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ with $description }}
<meta name="description" content="{{ . }}" />
{{ with partial "utils/description" . }}
<meta name="description" content="{{ trim (. | plainify) "\n" }}" />
{{ end }}
{{ with $keywords }}
<meta name="keywords" content="{{ delimit . "," }}" />

View File

@ -1,6 +1,8 @@
{{ if .IsHome -}}
{{ $thumbnail := default (default "brand.svg" .Site.Params.logo) (index (default slice .Site.Params.images) 0) | absURL }}<script type="application/ld+json">
{
{{ if eq .Kind "home" }}
{{ $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",
{{ with .Site.Params.GeekblogAuthor -}}
@ -8,30 +10,32 @@
{{- end }}
"name": "{{ .Site.Title }}",
"url": "{{ .Site.BaseURL }}",
{{- with .Site.Params.description }}
"description": "{{ . }}",
{{- with partial "utils/description" . }}
"description": "{{ trim (. | plainify) "\n" }}",
{{- end }}
"thumbnailUrl": "{{ $thumbnail }}"
{{- with .Site.Params.GeekblogContentLicense }},
"license": "{{ .name }}"
{{- end }}
}
</script>
}
</script>
{{ else if .IsPage }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ $description := default .Site.Params.description (default .Description .Summary) }}
{{ $ac := 0 }}
{{ $ac_max := default 0 (len $authors) }}
<script type="application/ld+json">
{
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ $ac := 0 }}
{{ $ac_max := default 0 (len $authors) }}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"articleSection": "{{ .Section }}",
"name": "{{ .Title | safeJS }}",
"headline": "{{ .Title | safeJS }}",
"alternativeHeadline": "{{ .Params.lead }}",
{{- with $description }}
"description": "{{ . }}",
{{- with .Params.lead }}
"alternativeHeadline": "{{ . }}",
{{- end }}
{{- with partial "utils/description" . }}
"description": "{{ trim (. | plainify) "\n" }}",
{{- end }}
"inLanguage": {{ .Site.Language.Lang }},
"isFamilyFriendly": "true",
@ -81,6 +85,6 @@
{{- with $tags := .Params.tags }}
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
{{- end }}
}
</script>
{{ end }}
}
</script>
{{- end -}}

View File

@ -1,16 +1,7 @@
<meta property="og:title" content="{{ .Title }}" />
<meta
property="og:description"
content="{{ with .Description }}
{{ . }}
{{ else }}
{{ if .IsPage }}
{{ .Summary }}
{{ else }}
{{ with .Site.Params.description }}{{ . }}{{ end }}
{{ end }}
{{ 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 }}" />

View File

@ -18,18 +18,9 @@
{{- end -}}
{{- end }}
<meta name="twitter:title" content="{{ .Title }}" />
<meta
name="twitter:description"
content="{{ with .Description }}
{{ . }}
{{ else }}
{{ if .IsPage }}
{{ .Summary }}
{{ else }}
{{ with .Site.Params.description }}{{ . }}{{ end }}
{{ end }}
{{ end -}}"
/>
{{ with .Site.Social.twitter -}}
{{- with partial "utils/description" . }}
<meta name="twitter:description" content="{{ trim (. | plainify) "\n" }}" />
{{- end }}
{{- with .Site.Social.twitter -}}
<meta name="twitter:site" content="@{{ . }}" />
{{ end -}}
{{- end }}

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