Skip to content

Commit 0d5a771

Browse files
committed
feat(structured-markup): Enhance event schema
Improve event schema generation, including OG image handling and video integration.
1 parent 1585ba0 commit 0d5a771

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

layouts/partials/structured-markup/event.html

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
{{/* layouts/partials/structured-markup/event.html */}}
1+
{{- /* layouts/partials/structured-markup/event.html */ -}}
22
{{ $page_context := . }}
3-
{{ $defaultOgImage := site.Params.metadata.image | default "images/og-image.png" | absLangURL }}
43

54
{{/* --- Date and Time Processing --- */}}
65
{{ $eventStartDate := "" }}{{ $eventEndDate := "" }}
@@ -22,48 +21,63 @@
2221
{{ $offset = "Z" }}
2322
{{ end }}
2423

25-
{{/* --- Image Processing --- */}}
26-
{{ $imagePath := $page_context.Params.image }}
27-
{{ $resolvedImageURL := "" }}
28-
{{ if $imagePath }}
29-
{{ if hasPrefix $imagePath "/" }}
30-
{{ $resolvedImageURL = $imagePath | absLangURL }}
31-
{{ else }}
32-
{{ with $page_context.Resources.GetMatch $imagePath }}
33-
{{ $resolvedImageURL = .Permalink }}
34-
{{ else }}
35-
{{ with resources.Get $imagePath }}
36-
{{ $resolvedImageURL = .Permalink }}
37-
{{ else }}
38-
{{ $resolvedImageURL = printf "%s%s" $page_context.RelPermalink $imagePath | absLangURL }}
24+
{{/* --- Image Processing: Create a definitive list of image URLs for the schema --- */}}
25+
{{ $imageUrls := slice }}
26+
{{ if .File }}
27+
{{ $pageSlug := path.Base .File.Dir }}
28+
{{ $suffixes := slice "16x9" "4x3" "1x1" }}
29+
{{ range $suffixes }}
30+
{{ $ogImageName := printf "%s-og-%s.jpg" $pageSlug . }}
31+
{{ with $page_context.Resources.GetMatch $ogImageName }}
32+
{{ $imageUrls = $imageUrls | append .Permalink }}
3933
{{ end }}
4034
{{ end }}
4135
{{ end }}
36+
37+
{{/* If no generated OG images are found, fall back to the front matter 'image' param */}}
38+
{{ if not $imageUrls }}
39+
{{ with $page_context.Params.image }}
40+
{{ $fmImage := . }}
41+
{{ with $page_context.Resources.GetMatch $fmImage }}
42+
{{ $imageUrls = slice .Permalink }}
4243
{{ else }}
43-
{{ $resolvedImageURL = $defaultOgImage }}
44+
{{ $imageUrls = slice ($fmImage | absLangURL) }}
45+
{{ end }}
46+
{{ end }}
47+
{{ end }}
48+
49+
{{/* If still no images, fall back to the site's default OG image */}}
50+
{{ if not $imageUrls }}
51+
{{ with site.Params.metadata.image }}
52+
{{ $imageUrls = slice (. | absLangURL) }}
53+
{{ end }}
4454
{{ end }}
4555

4656
{{/* --- Event Status Logic --- */}}
4757
{{ $eventStatus := "https://schema.org/EventScheduled" }}
4858
{{ if eq .Params.upcoming false }}
49-
{{/* Event has passed. Google infers this from date, but we can be explicit if needed.
50-
For now, we'll let the presence of a VideoObject signal its new state. */}}
59+
{{/* Google infers past events from date. Can add specific statuses like EventMovedOnline if needed. */}}
5160
{{ end }}
5261

5362
{{/* --- Video Object Logic --- */}}
5463
{{ $videoObject := "" }}
5564
{{ with .Params.video }}
65+
{{/* Use the main imageUrls if they exist (from OG images), otherwise fallback to YouTube's default thumbnail */}}
66+
{{ $thumbnailUrls := $imageUrls }}
67+
{{ if not $thumbnailUrls }}
68+
{{ $thumbnailUrls = slice (printf "https://i.ytimg.com/vi/%s/maxresdefault.jpg" .) }}
69+
{{ end }}
70+
5671
{{ $videoObject = dict
5772
"@type" "VideoObject"
5873
"name" $page_context.Title
5974
"description" $page_context.Description
60-
"thumbnailUrl" (printf "https://i.ytimg.com/vi/%s/maxresdefault.jpg" .)
61-
"uploadDate" ($page_context.Date.Format "2006-01-02")
75+
"thumbnailUrl" $thumbnailUrls
76+
"uploadDate" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
6277
"embedUrl" (printf "https://www.youtube.com/embed/%s" .)
6378
}}
6479
{{ end }}
6580

66-
6781
{{/* --- Main Event Schema Construction --- */}}
6882
{{ $eventLD := dict
6983
"@context" "https://schema.org"
@@ -77,7 +91,7 @@
7791
"@type" "VirtualLocation"
7892
"url" (cond (ne .Params.video "") (printf "https://www.youtube.com/watch?v=%s" .Params.video) "https://youtube.com/@openneuromorphic")
7993
)
80-
"image" (slice $resolvedImageURL)
94+
"image" $imageUrls
8195
"description" $page_context.Description
8296
"offers" (dict
8397
"@type" "Offer"
@@ -110,6 +124,7 @@
110124
{{ end }}
111125
{{ $eventLD = merge $eventLD (dict "performer" $performers) }}
112126
{{ end }}
127+
113128
{{ $eventLD = merge $eventLD (dict "organizer" (dict "@type" "Organization" "name" "Open Neuromorphic" "url" (absLangURL "/"))) }}
114129

115130
{{ return $eventLD }}

0 commit comments

Comments
 (0)