Skip to content

Commit 6d8655e

Browse files
committed
feat(event.html): Enhance event structured data
Adds video object and improves schema accuracy.
1 parent b5051c3 commit 6d8655e

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

layouts/partials/structured-markup/event.html

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
{{/* layouts/partials/structured-markup/event.html */}}
12
{{ $page_context := . }}
23
{{ $defaultOgImage := site.Params.metadata.image | default "images/og-image.png" | absLangURL }}
4+
5+
{{/* --- Date and Time Processing --- */}}
36
{{ $eventStartDate := "" }}{{ $eventEndDate := "" }}
47
{{ if $page_context.Params.start_time }}
58
{{ $eventStartDate = printf "%sT%s" ($page_context.Date.Format "2006-01-02") $page_context.Params.start_time }}
@@ -19,6 +22,7 @@
1922
{{ $offset = "Z" }}
2023
{{ end }}
2124

25+
{{/* --- Image Processing --- */}}
2226
{{ $imagePath := $page_context.Params.image }}
2327
{{ $resolvedImageURL := "" }}
2428
{{ if $imagePath }}
@@ -28,24 +32,53 @@
2832
{{ with $page_context.Resources.GetMatch $imagePath }}
2933
{{ $resolvedImageURL = .Permalink }}
3034
{{ else }}
35+
{{ with resources.Get $imagePath }}
36+
{{ $resolvedImageURL = .Permalink }}
37+
{{ else }}
3138
{{ $resolvedImageURL = printf "%s%s" $page_context.RelPermalink $imagePath | absLangURL }}
3239
{{ end }}
3340
{{ end }}
41+
{{ end }}
3442
{{ else }}
3543
{{ $resolvedImageURL = $defaultOgImage }}
3644
{{ end }}
3745

46+
{{/* --- Event Status Logic --- */}}
47+
{{ $eventStatus := "https://schema.org/EventScheduled" }}
48+
{{ 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. */}}
51+
{{ end }}
52+
53+
{{/* --- Video Object Logic --- */}}
54+
{{ $videoObject := "" }}
55+
{{ with .Params.video }}
56+
{{ $videoObject = dict
57+
"@type" "VideoObject"
58+
"name" $page_context.Title
59+
"description" $page_context.Description
60+
"thumbnailUrl" (printf "https://i.ytimg.com/vi/%s/maxresdefault.jpg" .)
61+
"uploadDate" ($page_context.Date.Format "2006-01-02")
62+
"embedUrl" (printf "https://www.youtube.com/embed/%s" .)
63+
}}
64+
{{ end }}
65+
66+
67+
{{/* --- Main Event Schema Construction --- */}}
3868
{{ $eventLD := dict
3969
"@context" "https://schema.org"
4070
"@type" "Event"
41-
"name" $page_context.Params.Title
71+
"name" $page_context.Title
4272
"startDate" (printf "%s%s" $eventStartDate $offset)
4373
"endDate" (printf "%s%s" $eventEndDate $offset)
44-
"eventStatus" "https://schema.org/EventScheduled"
74+
"eventStatus" $eventStatus
4575
"eventAttendanceMode" "https://schema.org/OnlineEventAttendanceMode"
46-
"location" (dict "@type" "VirtualLocation" "url" "https://youtube.com/@openneuromorphic")
76+
"location" (dict
77+
"@type" "VirtualLocation"
78+
"url" (cond (ne .Params.video "") (printf "https://www.youtube.com/watch?v=%s" .Params.video) "https://youtube.com/@openneuromorphic")
79+
)
4780
"image" (slice $resolvedImageURL)
48-
"description" $page_context.Params.Description
81+
"description" $page_context.Description
4982
"offers" (dict
5083
"@type" "Offer"
5184
"price" "0"
@@ -55,6 +88,9 @@
5588
"validFrom" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
5689
)
5790
}}
91+
92+
{{ if $videoObject }}{{ $eventLD = merge $eventLD (dict "video" $videoObject) }}{{ end }}
93+
5894
{{ if $page_context.Params.author }}
5995
{{ $authorList := slice }}
6096
{{ with $page_context.Params.author }}{{ if reflect.IsSlice . }}{{ $authorList = . }}{{ else }}{{ $authorList = slice . }}{{ end }}{{ end }}

0 commit comments

Comments
 (0)