|
1 |
| -{{/* layouts/partials/structured-markup/event.html */}} |
| 1 | +{{- /* layouts/partials/structured-markup/event.html */ -}} |
2 | 2 | {{ $page_context := . }}
|
3 |
| -{{ $defaultOgImage := site.Params.metadata.image | default "images/og-image.png" | absLangURL }} |
4 | 3 |
|
5 | 4 | {{/* --- Date and Time Processing --- */}}
|
6 | 5 | {{ $eventStartDate := "" }}{{ $eventEndDate := "" }}
|
|
22 | 21 | {{ $offset = "Z" }}
|
23 | 22 | {{ end }}
|
24 | 23 |
|
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 }} |
39 | 33 | {{ end }}
|
40 | 34 | {{ end }}
|
41 | 35 | {{ 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 }} |
42 | 43 | {{ 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 }} |
44 | 54 | {{ end }}
|
45 | 55 |
|
46 | 56 | {{/* --- Event Status Logic --- */}}
|
47 | 57 | {{ $eventStatus := "https://schema.org/EventScheduled" }}
|
48 | 58 | {{ 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. */}} |
51 | 60 | {{ end }}
|
52 | 61 |
|
53 | 62 | {{/* --- Video Object Logic --- */}}
|
54 | 63 | {{ $videoObject := "" }}
|
55 | 64 | {{ 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 | + |
56 | 71 | {{ $videoObject = dict
|
57 | 72 | "@type" "VideoObject"
|
58 | 73 | "name" $page_context.Title
|
59 | 74 | "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") |
62 | 77 | "embedUrl" (printf "https://www.youtube.com/embed/%s" .)
|
63 | 78 | }}
|
64 | 79 | {{ end }}
|
65 | 80 |
|
66 |
| - |
67 | 81 | {{/* --- Main Event Schema Construction --- */}}
|
68 | 82 | {{ $eventLD := dict
|
69 | 83 | "@context" "https://schema.org"
|
|
77 | 91 | "@type" "VirtualLocation"
|
78 | 92 | "url" (cond (ne .Params.video "") (printf "https://www.youtube.com/watch?v=%s" .Params.video) "https://youtube.com/@openneuromorphic")
|
79 | 93 | )
|
80 |
| -"image" (slice $resolvedImageURL) |
| 94 | +"image" $imageUrls |
81 | 95 | "description" $page_context.Description
|
82 | 96 | "offers" (dict
|
83 | 97 | "@type" "Offer"
|
|
110 | 124 | {{ end }}
|
111 | 125 | {{ $eventLD = merge $eventLD (dict "performer" $performers) }}
|
112 | 126 | {{ end }}
|
| 127 | + |
113 | 128 | {{ $eventLD = merge $eventLD (dict "organizer" (dict "@type" "Organization" "name" "Open Neuromorphic" "url" (absLangURL "/"))) }}
|
114 | 129 |
|
115 | 130 | {{ return $eventLD }}
|
0 commit comments