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> <head>
{{ partial "head/meta" . }} {{ partial "head/meta" . }}
<title> <title>
{{ if not (eq .Kind "home") }} {{- if eq .Kind "home" -}}
{{ partial "title" . }}{{ printf " | " }} {{ .Site.Title }}
{{ end }}{{ .Site.Title }} {{- else -}}
{{ printf "%s | %s" (partial "utils/title" .) .Site.Title }}
{{- end -}}
</title> </title>
{{ partial "head/favicons" . }} {{ partial "head/favicons" . }}

View File

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

View File

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

View File

@ -7,7 +7,10 @@
<picture> <picture>
{{ $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) }} {{ $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) }}
<source srcset="{{ $featured.Permalink }}" /> <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> </picture>
{{ with $source.Params.credits }} {{ with $source.Params.credits }}
<span>Credits: {{ . | $.Page.RenderString | safeHTML }}</span> <span>Credits: {{ . | $.Page.RenderString | safeHTML }}</span>
@ -16,7 +19,7 @@
{{ end }} {{ 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") }} {{ 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"> <div class="flex flex-wrap align-center gblog-post__meta gblog-post__meta--head">

View File

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

View File

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

View File

@ -1,5 +1,7 @@
{{ if .IsHome -}} {{ 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"> {{ $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", "@context": "http://schema.org",
"@type": "WebSite", "@type": "WebSite",
@ -8,8 +10,8 @@
{{- end }} {{- end }}
"name": "{{ .Site.Title }}", "name": "{{ .Site.Title }}",
"url": "{{ .Site.BaseURL }}", "url": "{{ .Site.BaseURL }}",
{{- with .Site.Params.description }} {{- with partial "utils/description" . }}
"description": "{{ . }}", "description": "{{ trim (. | plainify) "\n" }}",
{{- end }} {{- end }}
"thumbnailUrl": "{{ $thumbnail }}" "thumbnailUrl": "{{ $thumbnail }}"
{{- with .Site.Params.GeekblogContentLicense }}, {{- with .Site.Params.GeekblogContentLicense }},
@ -19,9 +21,9 @@
</script> </script>
{{ else if .IsPage }} {{ else if .IsPage }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }} {{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ $description := default .Site.Params.description (default .Description .Summary) }}
{{ $ac := 0 }} {{ $ac := 0 }}
{{ $ac_max := default 0 (len $authors) }} {{ $ac_max := default 0 (len $authors) }}
<script type="application/ld+json"> <script type="application/ld+json">
{ {
"@context": "http://schema.org", "@context": "http://schema.org",
@ -29,9 +31,11 @@
"articleSection": "{{ .Section }}", "articleSection": "{{ .Section }}",
"name": "{{ .Title | safeJS }}", "name": "{{ .Title | safeJS }}",
"headline": "{{ .Title | safeJS }}", "headline": "{{ .Title | safeJS }}",
"alternativeHeadline": "{{ .Params.lead }}", {{- with .Params.lead }}
{{- with $description }} "alternativeHeadline": "{{ . }}",
"description": "{{ . }}", {{- end }}
{{- with partial "utils/description" . }}
"description": "{{ trim (. | plainify) "\n" }}",
{{- end }} {{- end }}
"inLanguage": {{ .Site.Language.Lang }}, "inLanguage": {{ .Site.Language.Lang }},
"isFamilyFriendly": "true", "isFamilyFriendly": "true",
@ -83,4 +87,4 @@
{{- end }} {{- end }}
} }
</script> </script>
{{ end }} {{- end -}}

View File

@ -1,16 +1,7 @@
<meta property="og:title" content="{{ .Title }}" /> <meta property="og:title" content="{{ .Title }}" />
<meta {{ with partial "utils/description" . }}
property="og:description" <meta property="og:description" content="{{ trim (. | plainify) "\n" }}" />
content="{{ with .Description }}
{{ . }}
{{ else }}
{{ if .IsPage }}
{{ .Summary }}
{{ else }}
{{ with .Site.Params.description }}{{ . }}{{ end }}
{{ end }} {{ end }}
{{ end }}"
/>
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" /> <meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" /> <meta property="og:url" content="{{ .Permalink }}" />

View File

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