mirror of
https://github.com/thegeeklab/hugo-geekblog.git
synced 2024-11-24 05:50:40 +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>
|
||||
{{ 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" . }}
|
||||
|
@ -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 }}
|
||||
|
@ -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 }}
|
||||
|
@ -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">
|
||||
|
@ -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 }}
|
||||
|
@ -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 . "," }}" />
|
||||
|
@ -1,86 +1,90 @@
|
||||
{{ 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",
|
||||
{{ with .Site.Params.GeekblogAuthor -}}
|
||||
{{ with index $.Site.Data.authors . }}"author": "{{ .name }}",{{ end }}
|
||||
{{- end }}
|
||||
"name": "{{ .Site.Title }}",
|
||||
"url": "{{ .Site.BaseURL }}",
|
||||
{{- with .Site.Params.description }}
|
||||
"description": "{{ . }}",
|
||||
{{- end }}
|
||||
"thumbnailUrl": "{{ $thumbnail }}"
|
||||
{{- with .Site.Params.GeekblogContentLicense }},
|
||||
"license": "{{ .name }}"
|
||||
{{- end }}
|
||||
}
|
||||
</script>
|
||||
{{ 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 -}}
|
||||
{{ with index $.Site.Data.authors . }}"author": "{{ .name }}",{{ end }}
|
||||
{{- end }}
|
||||
"name": "{{ .Site.Title }}",
|
||||
"url": "{{ .Site.BaseURL }}",
|
||||
{{- with partial "utils/description" . }}
|
||||
"description": "{{ trim (. | plainify) "\n" }}",
|
||||
{{- end }}
|
||||
"thumbnailUrl": "{{ $thumbnail }}"
|
||||
{{- with .Site.Params.GeekblogContentLicense }},
|
||||
"license": "{{ .name }}"
|
||||
{{- end }}
|
||||
}
|
||||
</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">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
"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 }}"
|
||||
},
|
||||
{{- with $authors }}
|
||||
"author" : [
|
||||
{{- range sort . }}
|
||||
{{- with . -}}
|
||||
{{- $ac = (add $ac 1) }}
|
||||
{{- $author := index $.Site.Data.authors . }}
|
||||
{
|
||||
"@type": "Person",
|
||||
"name": "{{ $author.name }}"
|
||||
}{{ if lt $ac $ac_max }},{{ end }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
],
|
||||
{{- end }}
|
||||
"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 }}
|
||||
{{ $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 }}",
|
||||
{{- with .Params.lead }}
|
||||
"alternativeHeadline": "{{ . }}",
|
||||
{{- end }}
|
||||
{{- with partial "utils/description" . }}
|
||||
"description": "{{ trim (. | plainify) "\n" }}",
|
||||
{{- end }}
|
||||
"inLanguage": {{ .Site.Language.Lang }},
|
||||
"isFamilyFriendly": "true",
|
||||
"mainEntityOfPage": {
|
||||
"@type": "WebPage",
|
||||
"@id": "{{ .Permalink }}"
|
||||
},
|
||||
{{- with $authors }}
|
||||
"author" : [
|
||||
{{- range sort . }}
|
||||
{{- with . -}}
|
||||
{{- $ac = (add $ac 1) }}
|
||||
{{- $author := index $.Site.Data.authors . }}
|
||||
{
|
||||
"@type": "Person",
|
||||
"name": "{{ $author.name }}"
|
||||
}{{ if lt $ac $ac_max }},{{ end }}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
],
|
||||
{{- end }}
|
||||
"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 -}}
|
||||
|
@ -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 }}" />
|
||||
|
||||
|
@ -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 }}
|
||||
|
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