diff --git a/content/calendar/vam/friday-late/index.md b/content/calendar/vam/friday-late/index.md index 90b00e44..e2338370 100644 --- a/content/calendar/vam/friday-late/index.md +++ b/content/calendar/vam/friday-late/index.md @@ -15,6 +15,7 @@ timings: duration: PT3H30M - starts: 2024-08-30T18:30:00+01:00 duration: PT3H30M + attending: false - starts: 2024-09-27T18:30:00+01:00 duration: PT3H30M - starts: 2024-10-25T18:30:00+01:00 diff --git a/layouts/index.gmi b/layouts/index.gmi index da915797..867b6b5b 100644 --- a/layouts/index.gmi +++ b/layouts/index.gmi @@ -18,17 +18,7 @@ Some of my recent (and more substantial) writing. ## Upcoming events -{{ $allEvents := where .Site.RegularPages "Section" "calendar" -}} -{{- $upcomingEvents := slice -}} -{{- range $eventPage := $allEvents -}} - {{- range $eventPage.Params.timings -}} - {{- $event := dict "Title" $eventPage.Title "Page" $eventPage.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) -}} - {{- if $event.Date.Before time.Now }}{{ continue }}{{ end -}} - {{- $upcomingEvents = sort ($upcomingEvents | append $event) "Date" "asc" -}} - {{- break -}}{{/* Only show the first on the list */}} - {{- end -}} -{{- end -}} - +{{- $upcomingEvents := partial "upcoming-events.obj" }} {{- if ge (len $upcomingEvents) 2 -}} Maybe you'll see me at **{{ (index $upcomingEvents 0).Title }}** on {{ (partial "year-relative-date.html" (index $upcomingEvents 0).Date) | plainify }}, or **{{ (index $upcomingEvents 1).Title }}** on {{ (partial "year-relative-date.html" (index $upcomingEvents 1).Date) | plainify }}. Get in touch if you'd like to go to these, or any other eventsâș, together! diff --git a/layouts/partials/post-previews.html b/layouts/partials/post-previews.html index 7a8ecd65..6dfc9544 100644 --- a/layouts/partials/post-previews.html +++ b/layouts/partials/post-previews.html @@ -27,17 +27,8 @@

{{ partial "svg.html" (dict "name" "document") }} Check out all my longer posts, or read through my thoughts on others' writing.

- {{- $allEvents := where .Site.RegularPages "Section" "calendar" -}} - {{- $upcomingEvents := slice }} - {{- range $eventPage := $allEvents -}} - {{ range $eventPage.Params.timings }} - {{ $event := dict "Title" $eventPage.Title "Page" $eventPage.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) }} - {{ if $event.Date.Before time.Now }}{{ continue }}{{ end }} - {{ $upcomingEvents = sort ($upcomingEvents | append $event) "Date" "asc" }} - {{ break }}{{/* Only show the first on the list */}} - {{ end }} - {{- end -}} - + {{- $upcomingEvents := partial "upcoming-events.obj" }} + {{ $upcomingEvents }} {{ if ge (len $upcomingEvents) 2 }}

diff --git a/layouts/partials/upcoming-events.obj b/layouts/partials/upcoming-events.obj new file mode 100644 index 00000000..d23f74fc --- /dev/null +++ b/layouts/partials/upcoming-events.obj @@ -0,0 +1,12 @@ +{{- $allEvents := where site.RegularPages "Section" "calendar" -}} +{{- $upcomingEvents := slice }} +{{- range $eventPage := $allEvents -}} + {{ range $eventPage.Params.timings }} + {{ $event := dict "Title" $eventPage.Title "Page" $eventPage.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) }} + {{ if $event.Date.Before time.Now }}{{ continue }}{{ end }} + {{ if eq .attending false }}{{ continue }}{{ end }} + {{ $upcomingEvents = sort ($upcomingEvents | append $event) "Date" "asc" }} + {{ break }}{{/* Only show the first on the list */}} + {{ end }} +{{- end -}} +{{- return $upcomingEvents -}} \ No newline at end of file