mirror of
https://github.com/thegeeklab/hugo-geekblog.git
synced 2024-11-24 14:00:42 +00:00
refactor: unify title and description handling in meta files (#189)
This commit is contained in:
parent
b83812d09f
commit
91f44eb3a5
@ -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" . }}
|
||||||
|
@ -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 }}
|
||||||
|
@ -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 }}
|
||||||
|
@ -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">
|
||||||
|
@ -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 }}
|
||||||
|
@ -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 . "," }}" />
|
||||||
|
@ -1,86 +1,90 @@
|
|||||||
{{ 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 }}
|
||||||
{
|
|
||||||
"@context": "http://schema.org",
|
<script type="application/ld+json">
|
||||||
"@type": "WebSite",
|
{
|
||||||
{{ with .Site.Params.GeekblogAuthor -}}
|
"@context": "http://schema.org",
|
||||||
{{ with index $.Site.Data.authors . }}"author": "{{ .name }}",{{ end }}
|
"@type": "WebSite",
|
||||||
{{- end }}
|
{{ with .Site.Params.GeekblogAuthor -}}
|
||||||
"name": "{{ .Site.Title }}",
|
{{ with index $.Site.Data.authors . }}"author": "{{ .name }}",{{ end }}
|
||||||
"url": "{{ .Site.BaseURL }}",
|
{{- end }}
|
||||||
{{- with .Site.Params.description }}
|
"name": "{{ .Site.Title }}",
|
||||||
"description": "{{ . }}",
|
"url": "{{ .Site.BaseURL }}",
|
||||||
{{- end }}
|
{{- with partial "utils/description" . }}
|
||||||
"thumbnailUrl": "{{ $thumbnail }}"
|
"description": "{{ trim (. | plainify) "\n" }}",
|
||||||
{{- with .Site.Params.GeekblogContentLicense }},
|
{{- end }}
|
||||||
"license": "{{ .name }}"
|
"thumbnailUrl": "{{ $thumbnail }}"
|
||||||
{{- end }}
|
{{- with .Site.Params.GeekblogContentLicense }},
|
||||||
}
|
"license": "{{ .name }}"
|
||||||
</script>
|
{{- end }}
|
||||||
|
}
|
||||||
|
</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",
|
||||||
"@type": "BlogPosting",
|
"@type": "BlogPosting",
|
||||||
"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 }}
|
||||||
{{- end }}
|
{{- with partial "utils/description" . }}
|
||||||
"inLanguage": {{ .Site.Language.Lang }},
|
"description": "{{ trim (. | plainify) "\n" }}",
|
||||||
"isFamilyFriendly": "true",
|
{{- end }}
|
||||||
"mainEntityOfPage": {
|
"inLanguage": {{ .Site.Language.Lang }},
|
||||||
"@type": "WebPage",
|
"isFamilyFriendly": "true",
|
||||||
"@id": "{{ .Permalink }}"
|
"mainEntityOfPage": {
|
||||||
},
|
"@type": "WebPage",
|
||||||
{{- with $authors }}
|
"@id": "{{ .Permalink }}"
|
||||||
"author" : [
|
},
|
||||||
{{- range sort . }}
|
{{- with $authors }}
|
||||||
{{- with . -}}
|
"author" : [
|
||||||
{{- $ac = (add $ac 1) }}
|
{{- range sort . }}
|
||||||
{{- $author := index $.Site.Data.authors . }}
|
{{- with . -}}
|
||||||
{
|
{{- $ac = (add $ac 1) }}
|
||||||
"@type": "Person",
|
{{- $author := index $.Site.Data.authors . }}
|
||||||
"name": "{{ $author.name }}"
|
{
|
||||||
}{{ if lt $ac $ac_max }},{{ end }}
|
"@type": "Person",
|
||||||
{{- end -}}
|
"name": "{{ $author.name }}"
|
||||||
{{- end }}
|
}{{ if lt $ac $ac_max }},{{ end }}
|
||||||
],
|
{{- end -}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
"copyrightHolder" : "{{ .Site.Title }}",
|
],
|
||||||
"copyrightYear" : "{{ .Date.Format "2006" }}",
|
{{- end }}
|
||||||
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
"copyrightHolder" : "{{ .Site.Title }}",
|
||||||
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
"copyrightYear" : "{{ .Date.Format "2006" }}",
|
||||||
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||||
"publisher":{
|
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||||
"@type":"Organization",
|
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeJS }}",
|
||||||
"name": {{ .Site.Title }},
|
"publisher":{
|
||||||
"url": {{ .Site.BaseURL }},
|
"@type":"Organization",
|
||||||
"logo": {
|
"name": {{ .Site.Title }},
|
||||||
"@type": "ImageObject",
|
"url": {{ .Site.BaseURL }},
|
||||||
"url": "{{ (default "brand.svg" .Site.Params.logo) | absURL }}",
|
"logo": {
|
||||||
"width":"32",
|
"@type": "ImageObject",
|
||||||
"height":"32"
|
"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 := $.Resources.ByType "image" }}
|
||||||
{{- with $images := .Params.images }}
|
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image.Permalink | absURL }}" {{ end }}],
|
||||||
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image | absURL }}" {{ end }}],
|
{{- else }}
|
||||||
{{- end }}
|
{{- with $images := .Params.images }}
|
||||||
{{- end }}
|
"image": [ {{ range $i, $image := $images }}{{ if $i }}, {{ end }}"{{ $image | absURL }}" {{ end }}],
|
||||||
"url" : "{{ .Permalink }}",
|
{{- end }}
|
||||||
"wordCount" : "{{ .WordCount }}",
|
{{- end }}
|
||||||
{{- with $tags := .Params.tags }}
|
"url" : "{{ .Permalink }}",
|
||||||
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
|
"wordCount" : "{{ .WordCount }}",
|
||||||
{{- end }}
|
{{- with $tags := .Params.tags }}
|
||||||
}
|
"genre" : [ {{ range $i, $tag := $tags }}{{ if $i }}, {{ end }}"{{ $tag }}" {{ end }}]
|
||||||
</script>
|
{{- end }}
|
||||||
{{ end }}
|
}
|
||||||
|
</script>
|
||||||
|
{{- end -}}
|
||||||
|
@ -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 }}
|
{{ end }}
|
||||||
{{ . }}
|
|
||||||
{{ else }}
|
|
||||||
{{ if .IsPage }}
|
|
||||||
{{ .Summary }}
|
|
||||||
{{ else }}
|
|
||||||
{{ with .Site.Params.description }}{{ . }}{{ 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 }}" />
|
||||||
|
|
||||||
|
@ -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 }}
|
||||||
|
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…
Reference in New Issue
Block a user