From 392708d390b3b48047131bc11324526b59f99d7a Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Thu, 30 Dec 2021 15:30:40 +0100 Subject: [PATCH] chore: include microformtas templates to fix opengraph (#132) --- .../content/posts/usage/getting-started.md | 2 +- layouts/partials/head/microformats.html | 4 +- layouts/partials/microformats/opengraph.html | 46 +++++++++++++++++++ .../partials/microformats/twitter_cards.html | 25 ++++++++++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 layouts/partials/microformats/opengraph.html create mode 100644 layouts/partials/microformats/twitter_cards.html diff --git a/exampleSite/content/posts/usage/getting-started.md b/exampleSite/content/posts/usage/getting-started.md index ab1a751..738c4da 100644 --- a/exampleSite/content/posts/usage/getting-started.md +++ b/exampleSite/content/posts/usage/getting-started.md @@ -124,7 +124,7 @@ To prepare your new site environment just a few steps are required: If you want to add some demo data you could use the content from the [Hugo basic example](https://github.com/gohugoio/hugoBasicExample): ```Shell - curl -L https://github.com/gohugoio/hugoBasicExample/archive/main.tar.gz | tar -xz --exclude "config*" --exclude "LICENSE" --exclude "README*" --strip-components=1 + curl -L https://github.com/gohugoio/hugoBasicExample/archive/master.tar.gz | tar -xz --exclude "config*" --exclude "LICENSE" --exclude "README*" --strip-components=1 ``` ### Option 1: Download pre-build release bundle diff --git a/layouts/partials/head/microformats.html b/layouts/partials/head/microformats.html index 47183f7..1e76fda 100644 --- a/layouts/partials/head/microformats.html +++ b/layouts/partials/head/microformats.html @@ -1,2 +1,2 @@ -{{ template "_internal/opengraph.html" . }} -{{ template "_internal/twitter_cards.html" . }} +{{ partial "microformats/opengraph.html" . }} +{{ partial "microformats/twitter_cards.html" . }} diff --git a/layouts/partials/microformats/opengraph.html b/layouts/partials/microformats/opengraph.html new file mode 100644 index 0000000..b6d3532 --- /dev/null +++ b/layouts/partials/microformats/opengraph.html @@ -0,0 +1,46 @@ + + + + + +{{- with $.Params.images -}} +{{- range first 6 . }}{{ end -}} +{{- else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- with $featured -}} + +{{- else -}} +{{- with $.Site.Params.images }}{{ end -}} +{{- end -}} +{{- end -}} + +{{- if .IsPage }} +{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} + +{{ with .PublishDate }}{{ end }} +{{ with .Lastmod }}{{ end }} +{{- end -}} + +{{- with .Params.audio }}{{ end }} +{{- with .Params.locale }}{{ end }} +{{- with .Site.Params.title }}{{ end }} +{{- with .Params.videos }}{{- range . }} + +{{ 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 }}{{- range $name := . }} + {{- $series := index $siteSeries ($name | urlize) }} + {{- range $page := first 6 $series.Pages }} + {{- if ne $page.Permalink $permalink }}{{ end }} + {{- end }} +{{ end }}{{ end }} +{{- end }} + +{{- /* Facebook Page Admin ID for Domain Insights */}} +{{- with .Site.Social.facebook_admin }}{{ end }} diff --git a/layouts/partials/microformats/twitter_cards.html b/layouts/partials/microformats/twitter_cards.html new file mode 100644 index 0000000..de73649 --- /dev/null +++ b/layouts/partials/microformats/twitter_cards.html @@ -0,0 +1,25 @@ + +{{- with $.Params.images -}} + + +{{ else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- with $featured -}} + + +{{- else -}} +{{- with $.Site.Params.images -}} + + +{{ else -}} + +{{- end -}} +{{- end -}} +{{- end }} + + +{{ with .Site.Social.twitter -}} + +{{ end -}}