Skip to content

Commit a1a0df4

Browse files
authored
Update to add banner to older events. (#15598)
* Update to add banner to older events. * Delete ISSUE-12213-PLAN.md
1 parent 1ce4573 commit a1a0df4

File tree

4 files changed

+223
-0
lines changed

4 files changed

+223
-0
lines changed

themes/devopsdays-theme/layouts/event/single.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{- if eq .File.BaseFileName "welcome" -}}
66
{{- partial "welcome.html" . -}}
77
{{- else -}}
8+
{{- partial "events/non-current-banner.html" . -}}
89
<h1>devopsdays {{ $e.city }} - {{ .Title }}</h1>
910
{{ .Content }}
1011
{{- end -}}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{{- /*
2+
Banner to display on non-current event pages, indicating this is not the current event
3+
and providing a link to the current event for that city.
4+
*/ -}}
5+
6+
{{- $e := partial "functions/get-event-data" . -}}
7+
8+
{{- if and $e $e.city $e.name -}}
9+
{{- /* Get the current event for this city - pass page context */ -}}
10+
{{- $currentEvent := partial "functions/get-current-event-for-city" . -}}
11+
12+
{{- /* Extract year from current event being viewed */ -}}
13+
{{- $currentViewYear := 0 -}}
14+
{{- if $e.year -}}
15+
{{- $currentViewYear = int $e.year -}}
16+
{{- else if $e.name -}}
17+
{{- $yearStr := index (split $e.name "-") 0 -}}
18+
{{- $currentViewYear = int $yearStr -}}
19+
{{- end -}}
20+
21+
{{- /* Extract year from current event found */ -}}
22+
{{- $currentEventYear := 0 -}}
23+
{{- if and $currentEvent $currentEvent.year -}}
24+
{{- $currentEventYear = int $currentEvent.year -}}
25+
{{- else if and $currentEvent $currentEvent.name -}}
26+
{{- $yearStr := index (split $currentEvent.name "-") 0 -}}
27+
{{- $currentEventYear = int $yearStr -}}
28+
{{- end -}}
29+
30+
{{- /* Only show banner if there is a current event, it's different, and the current view is older or not the latest year */ -}}
31+
{{- if and $currentEvent (ne $currentEvent.name $e.name) (lt $currentViewYear $currentEventYear) -}}
32+
{{- /* Determine if current event being viewed is past or just older */ -}}
33+
{{- $isPast := false -}}
34+
{{- if and $e.enddate (time $e.enddate) -}}
35+
{{- $isPast = lt (time $e.enddate) now -}}
36+
{{- end -}}
37+
38+
<div class="row">
39+
<div class="col-md-12">
40+
<div class="alert alert-warning" role="alert">
41+
<strong>
42+
<i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
43+
{{- if $isPast -}}
44+
This is a past event from {{ $e.year }}.
45+
{{- else -}}
46+
This is an older event from {{ $e.year }}.
47+
{{- end -}}
48+
</strong>
49+
Visit the <a href='{{ (printf "/events/%s/" $currentEvent.name) }}' class="alert-link"><strong>{{ $currentEvent.year }} event page</strong></a> for current information.
50+
</div>
51+
</div>
52+
</div>
53+
{{- end -}}
54+
{{- end -}}
55+
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
{{- /*
2+
This function determines the "current" event for a given city/event_group.
3+
4+
Input: Page context (.) - the function will get the current event data from the page.
5+
6+
Returns: The event object for the current/most recent event, or empty dict if none found.
7+
8+
Logic:
9+
- First preference: Latest future event (enddate > now) by startdate
10+
- Second preference: Latest event by year (from name) for events without dates
11+
- Third preference: Latest past event by startdate
12+
*/ -}}
13+
14+
{{- $currentEvent := dict -}}
15+
{{- $e := partial "functions/get-event-data" . -}}
16+
17+
{{- if and $e $e.city -}}
18+
{{- /* Determine matching criteria: use event_group if available, otherwise city */ -}}
19+
{{- $matchTitle := $e.city -}}
20+
{{- if $e.event_group -}}
21+
{{- $matchTitle = $e.event_group -}}
22+
{{- end -}}
23+
24+
{{- /* Get all events with dates */ -}}
25+
{{- $allEvents := partial "functions/get-all-events" . -}}
26+
27+
{{- /* Get all events without dates (TBD) */ -}}
28+
{{- $tbdEvents := partial "functions/get-tbd-events" . -}}
29+
30+
{{- /* Combine both sets */ -}}
31+
{{- $allEventsIncludingTBD := $allEvents -}}
32+
{{- range $tbdEvents -}}
33+
{{- $allEventsIncludingTBD = $allEventsIncludingTBD | append . -}}
34+
{{- end -}}
35+
36+
{{- /* Filter events matching this city/event_group, excluding the current event */ -}}
37+
{{- $futureEvents := slice -}}
38+
{{- $eventsWithoutDates := slice -}}
39+
{{- $pastEvents := slice -}}
40+
41+
{{- range $allEventsIncludingTBD -}}
42+
{{- /* Skip if this is the event we're checking */ -}}
43+
{{- if and $e.name (ne .name $e.name) -}}
44+
{{- /* Check if event matches city or event_group (case-insensitive) */ -}}
45+
{{- $eventMatchTitle := .city -}}
46+
{{- if .event_group -}}
47+
{{- $eventMatchTitle = .event_group -}}
48+
{{- end -}}
49+
50+
{{- if or (eq (lower .city) (lower $matchTitle)) (eq (lower $eventMatchTitle) (lower $matchTitle)) -}}
51+
{{- /* Event matches this city/event_group */ -}}
52+
{{- if and .startdate .enddate -}}
53+
{{- /* Separate into future and past events based on enddate */ -}}
54+
{{- if gt (time .enddate) now -}}
55+
{{- $futureEvents = $futureEvents | append . -}}
56+
{{- else -}}
57+
{{- $pastEvents = $pastEvents | append . -}}
58+
{{- end -}}
59+
{{- else -}}
60+
{{- /* Event without dates - store separately */ -}}
61+
{{- $eventsWithoutDates = $eventsWithoutDates | append . -}}
62+
{{- end -}}
63+
{{- end -}}
64+
{{- end -}}
65+
{{- end -}}
66+
67+
{{- /* Determine current event with priority: latest year (future dates or TBD) > past */ -}}
68+
{{- $candidateEvent := dict -}}
69+
{{- /* Get the year of the event being viewed */ -}}
70+
{{- $viewingYear := 0 -}}
71+
{{- if $e.year -}}
72+
{{- $viewingYear = int $e.year -}}
73+
{{- else if $e.name -}}
74+
{{- $yearStr := index (split $e.name "-") 0 -}}
75+
{{- $viewingYear = int $yearStr -}}
76+
{{- end -}}
77+
78+
{{- /* Find the latest year among all OTHER events (excluding the one being viewed) */ -}}
79+
{{- $latestYear := 0 -}}
80+
{{- range $futureEvents -}}
81+
{{- $eventYear := 0 -}}
82+
{{- if .year -}}
83+
{{- $eventYear = int .year -}}
84+
{{- end -}}
85+
{{- if and $eventYear (gt $eventYear $latestYear) -}}
86+
{{- $latestYear = $eventYear -}}
87+
{{- end -}}
88+
{{- end -}}
89+
90+
{{- range $eventsWithoutDates -}}
91+
{{- $eventYear := 0 -}}
92+
{{- if .name -}}
93+
{{- $yearStr := index (split .name "-") 0 -}}
94+
{{- $eventYear = int $yearStr -}}
95+
{{- end -}}
96+
{{- if and $eventYear (gt $eventYear $latestYear) -}}
97+
{{- $latestYear = $eventYear -}}
98+
{{- end -}}
99+
{{- end -}}
100+
101+
{{- /* Only return a current event if another event has a newer year than what we're viewing */ -}}
102+
{{- if and (gt $latestYear 0) (gt $latestYear $viewingYear) -}}
103+
{{- /* Find the event from the latest year - prefer future with dates, then TBD */ -}}
104+
{{- $futureFromLatestYear := dict -}}
105+
{{- $tbdFromLatestYear := dict -}}
106+
107+
{{- /* Look for future events with dates from the latest year */ -}}
108+
{{- range $futureEvents -}}
109+
{{- $eventYear := 0 -}}
110+
{{- if .year -}}
111+
{{- $eventYear = int .year -}}
112+
{{- end -}}
113+
{{- if eq $eventYear $latestYear -}}
114+
{{- if or (not $futureFromLatestYear) (gt .startdate $futureFromLatestYear.startdate) -}}
115+
{{- $futureFromLatestYear = . -}}
116+
{{- end -}}
117+
{{- end -}}
118+
{{- end -}}
119+
120+
{{- /* Look for TBD events from the latest year */ -}}
121+
{{- range $eventsWithoutDates -}}
122+
{{- $eventYear := 0 -}}
123+
{{- if .name -}}
124+
{{- $yearStr := index (split .name "-") 0 -}}
125+
{{- $eventYear = int $yearStr -}}
126+
{{- end -}}
127+
{{- if eq $eventYear $latestYear -}}
128+
{{- $tbdFromLatestYear = . -}}
129+
{{- end -}}
130+
{{- end -}}
131+
132+
{{- /* Prefer future event with dates, fallback to TBD */ -}}
133+
{{- if $futureFromLatestYear -}}
134+
{{- $candidateEvent = $futureFromLatestYear -}}
135+
{{- else if $tbdFromLatestYear -}}
136+
{{- $candidateEvent = $tbdFromLatestYear -}}
137+
{{- end -}}
138+
{{- else if eq $latestYear 0 -}}
139+
{{- /* No future/TBD events found, check past events only if viewing year is not newer */ -}}
140+
{{- if gt (len $pastEvents) 0 -}}
141+
{{- $latestPastYear := 0 -}}
142+
{{- $latestPastEvent := dict -}}
143+
{{- range $pastEvents -}}
144+
{{- $eventYear := 0 -}}
145+
{{- if .year -}}
146+
{{- $eventYear = int .year -}}
147+
{{- end -}}
148+
{{- if and $eventYear (gt $eventYear $latestPastYear) -}}
149+
{{- $latestPastYear = $eventYear -}}
150+
{{- $latestPastEvent = . -}}
151+
{{- end -}}
152+
{{- end -}}
153+
{{- /* Only use past event if its year is newer than viewing year */ -}}
154+
{{- if and $latestPastEvent (gt $latestPastYear $viewingYear) -}}
155+
{{- $candidateEvent = $latestPastEvent -}}
156+
{{- end -}}
157+
{{- end -}}
158+
{{- end -}}
159+
160+
{{- $currentEvent = $candidateEvent -}}
161+
{{- end -}}
162+
163+
{{- return $currentEvent -}}
164+

themes/devopsdays-theme/layouts/partials/welcome.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{{- $e := partial "functions/get-event-data" . -}}
22
{{- $.Scratch.Set "contentdir" (printf "static/events/%s/" $e.name) -}}
33

4+
{{- /* Display banner for non-current events */ -}}
5+
{{- partial "events/non-current-banner.html" . -}}
6+
47
{{- if $e.masthead_background -}}
58
{{- if ne $e.masthead_background "" -}}
69
{{- if (where (readDir "static/events") "Name" $e.name) -}}

0 commit comments

Comments
 (0)