feat: add feature or thumbnail image to feeds (#194)

This commit is contained in:
Robert Kaussow 2022-02-06 16:59:16 +01:00 committed by GitHub
parent d8d211d6a5
commit 6f0cd03608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 84 deletions

View File

@ -19,7 +19,6 @@
{{ partial "head/rel-me" . }}
{{ partial "head/microformats" . }}
{{ partial "head/others" . }}
{{ partial "head/schema.html" . }}
{{ partial "head/custom" . }}
</head>

View File

@ -17,6 +17,7 @@
{{- end -}}
{{- end }}
<updated>{{ now.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
<generator uri="https://gohugo.io" version="{{ hugo.Version }}">Hugo</generator>
{{ with .Site.Params.GeekblogAuthor -}}
{{ with index $.Site.Data.authors . }}
<author>
@ -48,7 +49,12 @@
{{- 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>
{{ printf `<content type="html"><![CDATA[%s]]></content>` .Content | safeHTML }}
{{- $img := "" -}}
{{- with ($page.Resources.ByType "image").GetMatch "{*feature*,*cover*,*thumbnail*}" }}
{{- $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) -}}
{{- $img = printf `<img src="%s" width="%d" height="%d" alt="%s" /><br/>` $featured.Permalink $featured.Width $featured.Height (default (partial "utils/title" $page) .Params.description) -}}
{{- end }}
{{ printf `<content type="html"><![CDATA[%s%s]]></content>` $img .Content | safeHTML }}
{{ with .Site.Taxonomies }}
{{ range $taxo,$_ := . }} <!-- Defaults taxos: "tags", "categories" -->
{{ with $page.Param $taxo }}

View File

@ -36,6 +36,10 @@
"date_modified" : {{ (.Lastmod.Format "2006-01-02T15:04:05Z07:00") | jsonify }},
"id" : "{{ .Permalink }}",
"url" : "{{ .Permalink }}",
{{- with ($page.Resources.ByType "image").GetMatch "{*feature*,*cover*,*thumbnail*}" }}
{{- $featured := .Fill (printf "910x280 %s" (default "Smart" .Params.anchor)) -}}
"image" : "{{ $featured.Permalink }}",
{{- end }}
{{- with .Params.authors -}}
"authors" : [
{{- $authors := (sort .) }}

View File

@ -3,25 +3,25 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ hugo.Generator }}
{{ $keywords := default .Site.Params.Keywords .Keywords }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{- $keywords := default .Site.Params.Keywords .Keywords -}}
{{- $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors -}}
{{ with partial "utils/description" . }}
{{- with partial "utils/description" . }}
<meta name="description" content="{{ trim (. | plainify) "\n" }}" />
{{ end }}
{{ with $keywords }}
{{- end }}
{{- with $keywords }}
<meta name="keywords" content="{{ delimit . "," }}" />
{{ end }}
{{ with $authors }}
{{ $list := slice }}
{{ range sort . }}
{{ with . }}
{{ $author := index $.Site.Data.authors . }}
{{ $list = $list | append $author.name }}
{{ end }}
{{ end }}
{{- end }}
{{- with $authors }}
{{- $list := slice -}}
{{- range sort . }}
{{- with . }}
{{- $author := index $.Site.Data.authors . -}}
{{- $list = $list | append $author.name -}}
{{- end }}
{{- end }}
{{ with $list }}
{{- with $list }}
<meta name="author" content="{{ delimit . "," }}" />
{{ end }}
{{ end }}
{{- end }}
{{- end }}

View File

@ -1,2 +1,3 @@
{{ partial "microformats/opengraph.html" . }}
{{ partial "microformats/twitter_cards.html" . }}
{{ partial "microformats/schema.html" . }}

View File

@ -20,11 +20,11 @@
<svg class="icon {{ .icon }}"><use xlink:href="#{{ .icon }}"></use></svg>
{{ end }}
<a
href="{{ if .external }}
href="{{ if .external -}}
{{ .ref }}
{{ else }}
{{- else -}}
{{ relref $current .ref }}
{{ end }}"
{{- end }}"
class="gblog-footer__link"
>
{{ .name }}
@ -33,12 +33,12 @@
{{ else if eq $target "header" }}
<li>
<a
href="{{ if .external }}
href="{{ if .external -}}
{{ .ref }}
{{ else }}
{{- else -}}
{{ relref $current .ref }}
{{ end }}"
class="gblog-nav__entry {{ if $isCurrent }}is-active{{ end }}"
{{- end }}"
class="gblog-nav__entry{{ if $isCurrent }}{{ printf " %s" "is-active" }}{{ end }}"
>
{{ if $icon }}
<svg class="icon {{ .icon }}"><use xlink:href="#{{ .icon }}"></use></svg>

View File

@ -1,67 +1,74 @@
<meta property="og:title" content="{{ partial "utils/title" . }}" />
{{ with partial "utils/description" . }}
{{- 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 }}
{{- end }}
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
{{- with $.Params.images -}}
{{- with $.Params.images }}
{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
{{- else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- with $featured -}}
{{- else }}
{{- $featured := ($.Resources.ByType "image").GetMatch "{*feature*,*cover*,*thumbnail*}" -}}
{{- with $featured }}
<meta property="og:image" content="{{ $featured.Permalink }}" />
{{- else -}}
{{- else }}
{{- with $.Site.Params.images }}
<meta property="og:image" content="{{ index . 0 | absURL }}" />
{{ end -}}
{{- end -}}
{{- end -}}
{{- end }}
{{- end }}
{{- end }}
{{- if .IsPage }}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
<meta property="article:section" content="{{ .Section }}" />
{{ 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 -}}
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
{{- with .Params.locale }}<meta property="og:locale" content="{{ . }}" />{{ end }}
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ 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 }}
{{- 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 }}
{{- $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 }}
{{- end }}
{{- end }}
{{- end }}
{{ if .IsPage -}}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
<meta property="article:section" content="{{ .Section }}" />
{{- 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 }}
{{- with .Site.Social.facebook_admin }}
<meta property="fb:admins" content="{{ . }}" />
{{- end }}

View File

@ -1,5 +1,5 @@
{{ if eq .Kind "home" }}
{{ $thumbnail := default (default "brand.svg" .Site.Params.logo) (index (default slice .Site.Params.images) 0) | absURL }}
{{- 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">
{
@ -19,10 +19,10 @@
{{- end }}
}
</script>
{{ else if .IsPage }}
{{ $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors }}
{{ $ac := 0 }}
{{ $ac_max := default 0 (len $authors) }}
{{- else if .IsPage }}
{{- $authors := default (slice .Site.Params.GeekblogAuthor) .Params.authors -}}
{{- $ac := 0 -}}
{{- $ac_max := default 0 (len $authors) -}}
<script type="application/ld+json">
{
@ -87,4 +87,4 @@
{{- end }}
}
</script>
{{- end -}}
{{- end }}

View File

@ -1,21 +1,23 @@
{{- with $.Params.images -}}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="{{ index . 0 | absURL }}" />
{{ else -}}
{{- else }}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- with $featured -}}
{{- 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 -}}
{{- else }}
{{- with $.Site.Params.images }}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="{{ index . 0 | absURL }}" />
{{ else -}}
{{- else }}
<meta name="twitter:card" content="summary" />
{{- end -}}
{{- end -}}
{{- end }}
{{- end }}
{{- end }}
<meta name="twitter:title" content="{{ partial "utils/title" . }}" />
{{- with partial "utils/description" . }}