From 48cd01768bd81c857162ac3dd70c523ac2c19c23 Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Sun, 14 Apr 2024 19:30:41 +0200 Subject: sync theme --- .../partials/templates/_funcs/get-page-images.html | 47 ++++++++++++++++++++++ .../layouts/partials/templates/opengraph.html | 33 +++++++++------ .../layouts/partials/templates/schema_json.html | 9 ++++- .../layouts/partials/templates/twitter_cards.html | 43 +++++++++++--------- 4 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html (limited to 'themes/PaperMod/layouts/partials/templates') diff --git a/themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html b/themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html new file mode 100644 index 0000000..268ceb4 --- /dev/null +++ b/themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html @@ -0,0 +1,47 @@ +{{- $imgs := slice }} +{{- $imgParams := .Params.images }} +{{- $resources := .Resources.ByType "image" -}} +{{/* Find featured image resources if the images parameter is empty. */}} +{{- if not $imgParams }} + {{- $featured := $resources.GetMatch "*feature*" -}} + {{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} + {{- with $featured }} + {{- $imgs = $imgs | append (dict + "Image" . + "RelPermalink" .RelPermalink + "Permalink" .Permalink) }} + {{- end }} +{{- end }} +{{/* Use the first one of site images as the fallback. */}} +{{- if and (not $imgParams) (not $imgs) }} + {{- with site.Params.images }} + {{- $imgParams = first 1 . }} + {{- end }} +{{- end }} +{{/* Parse page's images parameter. */}} +{{- range $imgParams }} + {{- $img := . }} + {{- $url := urls.Parse $img }} + {{- if eq $url.Scheme "" }} + {{/* Internal image. */}} + {{- with $resources.GetMatch $img -}} + {{/* Image resource. */}} + {{- $imgs = $imgs | append (dict + "Image" . + "RelPermalink" .RelPermalink + "Permalink" .Permalink) }} + {{- else }} + {{- $imgs = $imgs | append (dict + "RelPermalink" (relURL $img) + "Permalink" (absURL $img) + ) }} + {{- end }} + {{- else }} + {{/* External image */}} + {{- $imgs = $imgs | append (dict + "RelPermalink" $img + "Permalink" $img + ) }} + {{- end }} +{{- end }} +{{- return $imgs }} diff --git a/themes/PaperMod/layouts/partials/templates/opengraph.html b/themes/PaperMod/layouts/partials/templates/opengraph.html index 9e8df14..95f037c 100644 --- a/themes/PaperMod/layouts/partials/templates/opengraph.html +++ b/themes/PaperMod/layouts/partials/templates/opengraph.html @@ -10,18 +10,10 @@ {{- end}} {{- else }} -{{- 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 -}} +{{- $images := partial "partials/templates/_funcs/get-page-images" . -}} +{{- range first 6 $images }} + +{{ end -}} {{- end }} {{- if .IsPage }} @@ -41,12 +33,27 @@ {{- /* If it is part of a series, link to related articles */}} {{- $permalink := .Permalink }} {{- $siteSeries := site.Taxonomies.series }} +{{- if $siteSeries }} {{ 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 }} + +{{- /* Deprecate site.Social.facebook_admin in favor of site.Params.social.facebook_admin */}} +{{- $facebookAdmin := "" }} +{{- with site.Params.social }} + {{- if reflect.IsMap . }} + {{- $facebookAdmin = .facebook_admin }} + {{- end }} +{{- else }} + {{- with site.Social.facebook_admin }} + {{- $facebookAdmin = . }} + {{- warnf "The social key in site configuration is deprecated. Use params.social.facebook_admin instead." }} + {{- end }} +{{- end }} {{- /* Facebook Page Admin ID for Domain Insights */}} -{{- with site.Social.facebook_admin }}{{ end }} +{{ with $facebookAdmin }}{{ end }} diff --git a/themes/PaperMod/layouts/partials/templates/schema_json.html b/themes/PaperMod/layouts/partials/templates/schema_json.html index 435cba5..ed4d689 100644 --- a/themes/PaperMod/layouts/partials/templates/schema_json.html +++ b/themes/PaperMod/layouts/partials/templates/schema_json.html @@ -4,7 +4,7 @@ "@context": "https://schema.org", "@type": "{{- ( site.Params.schema.publisherType | default "Organization") | title -}}", "name": {{ site.Title }}, - "url": {{ site.BaseURL }}, + "url": {{ site.Home.Permalink }}, "description": {{ site.Params.description | plainify | truncate 180 | safeHTML }}, "thumbnailUrl": {{ site.Params.assets.favicon | default "favicon.ico" | absURL }}, "sameAs": [ @@ -18,7 +18,7 @@ {{- else if (or .IsPage .IsSection) }} {{/* BreadcrumbList */}} -{{- $url := replace .Parent.Permalink ( printf "%s" site.BaseURL) "" }} +{{- $url := replace .Parent.Permalink ( printf "%s" site.Home.Permalink) "" }} {{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }} {{- $bc_list := (split $lang_url "/")}} @@ -80,6 +80,11 @@ {{- else -}} {{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}, {{- end}} + {{- else }} + {{- $images := partial "partials/templates/_funcs/get-page-images" . -}} + {{- with index $images 0 -}} + "image": {{ .Permalink }}, + {{- end }} {{- end -}} "datePublished": {{ .PublishDate }}, "dateModified": {{ .Lastmod }}, diff --git a/themes/PaperMod/layouts/partials/templates/twitter_cards.html b/themes/PaperMod/layouts/partials/templates/twitter_cards.html index bd46e37..46b0d04 100644 --- a/themes/PaperMod/layouts/partials/templates/twitter_cards.html +++ b/themes/PaperMod/layouts/partials/templates/twitter_cards.html @@ -6,28 +6,33 @@ {{- end}} {{- else }} -{{- with $.Params.images -}} - - -{{ else -}} -{{- $images := $.Resources.ByType "image" -}} -{{- $featured := $images.GetMatch "*feature*" -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} -{{- with $featured -}} - - +{{- $images := partial "partials/templates/_funcs/get-page-images" . -}} +{{- with index $images 0 -}} + + {{- else -}} -{{- with site.Params.images -}} - - -{{ else -}} {{- end -}} -{{- end -}} -{{- end }} {{- end }} -{{ with site.Social.twitter -}} - -{{ end -}} +{{- /* Deprecate site.Social.twitter in favor of site.Params.social.twitter */}} +{{- $twitterSite := "" }} +{{- with site.Params.social }} + {{- if reflect.IsMap . }} + {{- $twitterSite = .twitter }} + {{- end }} +{{- else }} + {{- with site.Social.twitter }} + {{- $twitterSite = . }} + {{- warnf "The social key in site configuration is deprecated. Use params.social.twitter instead." }} + {{- end }} +{{- end }} + +{{- with $twitterSite }} + {{- $content := . }} + {{- if not (strings.HasPrefix . "@") }} + {{- $content = printf "@%v" $twitterSite }} + {{- end }} + +{{- end }} -- cgit v1.2.3