summaryrefslogtreecommitdiff
path: root/themes/PaperMod/layouts/partials/templates
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2024-04-14 19:30:41 +0200
committerChristoph Cullmann <cullmann@kde.org>2024-04-14 19:30:41 +0200
commit48cd01768bd81c857162ac3dd70c523ac2c19c23 (patch)
tree0cb90363de46b6a9a593c5ab779198456b56e04c /themes/PaperMod/layouts/partials/templates
parent867a3c0c44033242d03f022134b1b38d9eca5008 (diff)
sync theme
Diffstat (limited to 'themes/PaperMod/layouts/partials/templates')
-rw-r--r--themes/PaperMod/layouts/partials/templates/_funcs/get-page-images.html47
-rw-r--r--themes/PaperMod/layouts/partials/templates/opengraph.html33
-rw-r--r--themes/PaperMod/layouts/partials/templates/schema_json.html9
-rw-r--r--themes/PaperMod/layouts/partials/templates/twitter_cards.html43
4 files changed, 98 insertions, 34 deletions
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 . }}<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 -}}
-<meta property="og:image" content="{{ $featured.Permalink }}"/>
-{{- else -}}
-{{- with site.Params.images }}<meta property="og:image" content="{{ index . 0 | absURL }}"/>{{ end -}}
-{{- end -}}
-{{- end -}}
+{{- $images := partial "partials/templates/_funcs/get-page-images" . -}}
+{{- range first 6 $images }}
+<meta property="og:image" content="{{ .Permalink }}" />
+{{ 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 }}<meta property="og:see_also" content="{{ $page.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 }}<meta property="fb:admins" content="{{ . }}" />{{ end }}
+{{ with $facebookAdmin }}<meta property="fb:admins" content="{{ . }}" />{{ 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 @@
</script>
{{- 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 @@
<meta name="twitter:image" content="{{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}" />
{{- end}}
{{- else }}
-{{- with $.Params.images -}}
-<meta name="twitter:card" content="summary_large_image"/>
-<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
-{{ else -}}
-{{- $images := $.Resources.ByType "image" -}}
-{{- $featured := $images.GetMatch "*feature*" -}}
-{{- 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 }}"/>
+{{- $images := partial "partials/templates/_funcs/get-page-images" . -}}
+{{- with index $images 0 -}}
+<meta name="twitter:card" content="summary_large_image" />
+<meta name="twitter:image" content="{{ .Permalink }}" />
{{- else -}}
-{{- with site.Params.images -}}
-<meta name="twitter:card" content="summary_large_image"/>
-<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
-{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
-{{- end -}}
-{{- 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 -}}
-<meta name="twitter:site" content="@{{ . }}"/>
-{{ 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 }}
+<meta name="twitter:site" content="{{ $content }}"/>
+{{- end }}