From 76b72515b6d8078268077bd9d96db493fb7bd6f8 Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Thu, 2 Nov 2023 00:30:06 +0100 Subject: structured metadata image like leading image --- layouts/partials/head.html | 48 ++++++++++----- layouts/partials/structured-data.html | 113 ++++++++++++++++++++++++---------- 2 files changed, 115 insertions(+), 46 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 38e31b7..35384ba 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,20 +1,38 @@ - - - {{ partial "structured-data.html" . }} + {{ partial "structured-data.html" . }} - {{ with resources.Get "scss/style.scss" | resources.ToCSS (dict "includePaths" (slice "node_modules") "targetPath" "css/style.css") | resources.Minify | fingerprint }} - - {{ end }} - - + {{ with resources.Get "scss/style.scss" | resources.ToCSS (dict "includePaths" (slice "node_modules") "targetPath" "css/style.css") | resources.Minify | fingerprint }} + + {{ end }} + + - {{ with resources.Get .Site.Params.favicon }} - - {{ end }} -{{ range .AlternativeOutputFormats -}} - {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} -{{ end -}} + {{ with resources.Get .Site.Params.favicon }} + + {{ end }} + {{ range .AlternativeOutputFormats -}} + {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{ end -}} - + + diff --git a/layouts/partials/structured-data.html b/layouts/partials/structured-data.html index 8d4e917..c55bcdd 100644 --- a/layouts/partials/structured-data.html +++ b/layouts/partials/structured-data.html @@ -1,51 +1,102 @@ + + {{ $title := print .Site.Title " | " .Title }} {{ if .IsHome }}{{ $title = .Site.Title }}{{ end }} {{ $title }} +{{ $image := "" }} +{{ if (.Resources.ByType "image").GetMatch "*featured*" }} + {{ $image = (.Resources.ByType "image").GetMatch "*featured*" }} +{{ else if resources.Get (index .Params.images 0) }} + {{ $image = resources.Get (index .Params.images 0) }} +{{ end }} -{{ with resources.Get (index .Params.images 0) }} -{{ $image := .Fill (default "400x400" $.Params.image_size) }} - - - +{{ if and $image (ne $image.MediaType.SubType "svg") }} + {{ $image := $image.Fit (default "768x400" $.Params.image_size) }} + + + {{ else }} - + {{ end }} - - -{{ with .Site.Social.twitter -}} - -{{ end -}} + + - - + + {{- if .IsPage }} -{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} - -{{ with .PublishDate }}{{ end }} -{{ with .Lastmod }}{{ end }} + {{- $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 }} +{{- 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 */}} {{- $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 }} + {{ 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 }} -- cgit v1.2.3