Skip to content

Commit 14eab7f

Browse files
committed
refactor: event.html: Use Article schema if no video
1 parent f27bdea commit 14eab7f

File tree

1 file changed

+75
-123
lines changed

1 file changed

+75
-123
lines changed
Lines changed: 75 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,82 @@
11
{{- /* layouts/partials/structured-markup/event.html */ -}}
22
{{ $page_context := . }}
3+
{{ $schemaToReturn := dict }}
34

4-
{{/* --- Date and Time Processing --- */}}
5-
{{ $eventStartDate := "" }}{{ $eventEndDate := "" }}
6-
{{ if $page_context.Params.start_time }}
7-
{{ $eventStartDate = printf "%sT%s" ($page_context.Date.Format "2006-01-02") $page_context.Params.start_time }}
8-
{{ else }}
9-
{{ $eventStartDate = $page_context.Date.Format "2006-01-02T00:00:00" }}
10-
{{ end }}
11-
{{ if $page_context.Params.end_time }}
12-
{{ $eventEndDate = printf "%sT%s" ($page_context.Date.Format "2006-01-02") $page_context.Params.end_time }}
13-
{{ else }}
14-
{{ $eventEndDate = $eventStartDate }}
15-
{{ end }}
5+
{{- /* --- Reusable Logic: Image and Author processing --- */ -}}
6+
{{- $imageUrls := slice -}}
7+
{{- if .File -}}
8+
{{- $pageSlug := path.Base .File.Dir -}}
9+
{{- $suffixes := slice "16x9" "4x3" "1x1" -}}
10+
{{- range $suffixes -}}
11+
{{- $ogImageName := printf "%s-og-%s.jpg" $pageSlug . -}}
12+
{{- with $page_context.Resources.GetMatch $ogImageName -}}
13+
{{- $imageUrls = $imageUrls | append .Permalink -}}
14+
{{- end -}}
15+
{{- end -}}
16+
{{- end -}}
17+
{{- if not $imageUrls -}}
18+
{{- with $page_context.Params.image -}}
19+
{{- $fmImage := . -}}
20+
{{- with $page_context.Resources.GetMatch $fmImage -}}
21+
{{- $imageUrls = slice .Permalink -}}
22+
{{- else -}}
23+
{{- $imageUrls = slice ($fmImage | absLangURL) -}}
24+
{{- end -}}
25+
{{- end -}}
26+
{{- end -}}
27+
{{- if not $imageUrls -}}{{- with site.Params.metadata.image -}}{{- $imageUrls = slice (. | absLangURL) -}}{{- end -}}{{- end -}}
1628

17-
{{ $offset := "" }}
18-
{{ with $page_context.Params.time_zone }}
19-
{{ if eq . "CET" }}{{ $offset = "+01:00" }}{{ else if eq . "CEST" }}{{ $offset = "+02:00" }}{{ else }}{{ $offset = "Z" }}{{ end }}
20-
{{ else }}
21-
{{ $offset = "Z" }}
22-
{{ end }}
29+
{{- $authorsLD := slice -}}
30+
{{- if $page_context.Params.author -}}
31+
{{- $authorList := slice -}}
32+
{{- with $page_context.Params.author -}}{{- if reflect.IsSlice . -}}{{- $authorList = . -}}{{- else -}}{{- $authorList = slice . -}}{{- end -}}{{- end -}}
33+
{{- range $authorList -}}
34+
{{- $authorName := . -}}
35+
{{- $nameForProcessing := $authorName | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" -}}
36+
{{- $contributorSlug := $nameForProcessing | anchorize -}}
37+
{{- $contributorPage := site.GetPage (printf "contributors/%s" $contributorSlug) -}}
38+
{{- $personDict := dict "@type" "Person" "name" $authorName -}}
39+
{{- if $contributorPage -}}{{- $personDict = merge $personDict (dict "url" ($contributorPage.Permalink | absLangURL)) -}}{{- end -}}
40+
{{- $authorsLD = $authorsLD | append $personDict -}}
41+
{{- end -}}
42+
{{- end -}}
2343

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 }}
33-
{{ end }}
34-
{{ end }}
35-
{{ end }}
44+
{{- /* --- Conditional Schema Generation --- */ -}}
45+
{{- if .Params.video -}}
46+
{{- /* This is a past event with a video. Use VideoObject schema. */ -}}
47+
{{- $videoLD := dict
48+
"@context" "https://schema.org"
49+
"@type" "VideoObject"
50+
"name" $page_context.Title
51+
"description" $page_context.Description
52+
"thumbnailUrl" $imageUrls
53+
"uploadDate" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
54+
"embedUrl" (printf "https://www.youtube.com/embed/%s" .Params.video)
55+
"publisher" (dict "@type" "Organization" "name" "Open Neuromorphic" "logo" (dict "@type" "ImageObject" "url" (absURL "ONM-logo.png")))
56+
-}}
57+
{{- if gt (len $authorsLD) 0 -}}
58+
{{- $videoLD = merge $videoLD (dict "author" $authorsLD) -}}
59+
{{- end -}}
60+
{{- $schemaToReturn = $videoLD -}}
3661

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 }}
43-
{{ else }}
44-
{{ $imageUrls = slice ($fmImage | absLangURL) }}
45-
{{ end }}
46-
{{ end }}
47-
{{ end }}
62+
{{- else -}}
63+
{{- /* This is an upcoming event or past event without video. Use Article schema. */ -}}
64+
{{- $articleLD := dict
65+
"@context" "https://schema.org"
66+
"@type" "Article"
67+
"headline" $page_context.Title
68+
"image" $imageUrls
69+
"datePublished" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
70+
"description" $page_context.Description
71+
"publisher" (dict "@type" "Organization" "name" "Open Neuromorphic" "logo" (dict "@type" "ImageObject" "url" (absURL "ONM-logo.png")))
72+
-}}
73+
{{- if $page_context.Lastmod -}}
74+
{{- $articleLD = merge $articleLD (dict "dateModified" ($page_context.Lastmod.Format "2006-01-02T15:04:05Z07:00")) -}}
75+
{{- end -}}
76+
{{- if gt (len $authorsLD) 0 -}}
77+
{{- $articleLD = merge $articleLD (dict "author" $authorsLD) -}}
78+
{{- end -}}
79+
{{- $schemaToReturn = $articleLD -}}
80+
{{- end -}}
4881

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 }}
54-
{{ end }}
55-
56-
{{/* --- Event Status Logic --- */}}
57-
{{ $eventStatus := "https://schema.org/EventScheduled" }}
58-
{{ if eq .Params.upcoming false }}
59-
{{/* Google infers past events from date. Can add specific statuses like EventMovedOnline if needed. */}}
60-
{{ end }}
61-
62-
{{/* --- Video Object Logic --- */}}
63-
{{ $videoObject := "" }}
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-
71-
{{ $videoObject = dict
72-
"@type" "VideoObject"
73-
"name" $page_context.Title
74-
"description" $page_context.Description
75-
"thumbnailUrl" $thumbnailUrls
76-
"uploadDate" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
77-
"embedUrl" (printf "https://www.youtube.com/embed/%s" .)
78-
}}
79-
{{ end }}
80-
81-
{{/* --- Main Event Schema Construction --- */}}
82-
{{ $eventLD := dict
83-
"@context" "https://schema.org"
84-
"@type" "Event"
85-
"name" $page_context.Title
86-
"startDate" (printf "%s%s" $eventStartDate $offset)
87-
"endDate" (printf "%s%s" $eventEndDate $offset)
88-
"eventStatus" $eventStatus
89-
"eventAttendanceMode" "https://schema.org/OnlineEventAttendanceMode"
90-
"location" (dict
91-
"@type" "VirtualLocation"
92-
"url" (cond (ne .Params.video "") (printf "https://www.youtube.com/watch?v=%s" .Params.video) "https://youtube.com/@openneuromorphic")
93-
)
94-
"image" $imageUrls
95-
"description" $page_context.Description
96-
"offers" (dict
97-
"@type" "Offer"
98-
"price" "0"
99-
"priceCurrency" "USD"
100-
"availability" "https://schema.org/InStock"
101-
"url" ($page_context.Permalink | absLangURL)
102-
"validFrom" ($page_context.Date.Format "2006-01-02T15:04:05Z07:00")
103-
)
104-
}}
105-
106-
{{ if $videoObject }}{{ $eventLD = merge $eventLD (dict "video" $videoObject) }}{{ end }}
107-
108-
{{ if $page_context.Params.author }}
109-
{{ $authorList := slice }}
110-
{{ with $page_context.Params.author }}{{ if reflect.IsSlice . }}{{ $authorList = . }}{{ else }}{{ $authorList = slice . }}{{ end }}{{ end }}
111-
112-
{{ $performers := slice }}
113-
{{ range $authorList }}
114-
{{ $authorName := . }}
115-
{{ $nameForProcessing := $authorName | replaceRE "[.]" "" | replaceRE "ć" "c" | replaceRE "Ć" "C" }}
116-
{{ $contributorSlug := $nameForProcessing | anchorize }}
117-
{{ $contributorPage := site.GetPage (printf "contributors/%s" $contributorSlug) }}
118-
119-
{{ $personDict := dict "@type" "Person" "name" $authorName }}
120-
{{ if $contributorPage }}
121-
{{ $personDict = merge $personDict (dict "url" ($contributorPage.Permalink | absLangURL)) }}
122-
{{ end }}
123-
{{ $performers = $performers | append $personDict }}
124-
{{ end }}
125-
{{ $eventLD = merge $eventLD (dict "performer" $performers) }}
126-
{{ end }}
127-
128-
{{ $eventLD = merge $eventLD (dict "organizer" (dict "@type" "Organization" "name" "Open Neuromorphic" "url" (absLangURL "/"))) }}
129-
130-
{{ return $eventLD }}
82+
{{- return $schemaToReturn -}}

0 commit comments

Comments
 (0)