Skip to content

Commit

Permalink
feature: add links to nearby upcoming events to all event pages
Browse files Browse the repository at this point in the history
  • Loading branch information
flopp committed Apr 17, 2024
1 parent 3748214 commit 3532a1b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
74 changes: 51 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type Location struct {
City string
Country string
Geo string
Lat float64
Lon float64
Distance string
Direction string
}
Expand Down Expand Up @@ -155,32 +157,33 @@ func createLocation(locationS, coordinatesS string) Location {
direction = utils.ApproxDirection(b)
}

return Location{locationS, country, coordinates, distance, direction}
return Location{locationS, country, coordinates, lat, lon, distance, direction}
}

type Event struct {
Type string
Name string
NameOld string
Time string
TimeRange utils.TimeRange
Old bool
Status string
Cancelled bool
Special bool
Location Location
Details string
Details2 template.HTML
Url string
RawTags []string
Tags []*Tag
RawSeries []string
Series []*Serie
Links []NameUrl
Added string
New bool
Prev *Event
Next *Event
Type string
Name string
NameOld string
Time string
TimeRange utils.TimeRange
Old bool
Status string
Cancelled bool
Special bool
Location Location
Details string
Details2 template.HTML
Url string
RawTags []string
Tags []*Tag
RawSeries []string
Series []*Serie
Links []NameUrl
Added string
New bool
Prev *Event
Next *Event
UpcomingNear []*Event
}

func (event Event) IsSeparator() bool {
Expand Down Expand Up @@ -221,6 +224,7 @@ func createSeparatorEvent(label string) *Event {
true,
nil,
nil,
nil,
}
}

Expand Down Expand Up @@ -713,6 +717,7 @@ func fetchEvents(config ConfigData, srv *sheets.Service, today time.Time, eventT
false,
nil,
nil,
nil,
})
}

Expand Down Expand Up @@ -901,6 +906,27 @@ func findPrevNextEvents(events []*Event) {
}
}

func findUpcomingNearEvents(events []*Event, upcomingEvents []*Event, maxDistanceKM float64, count int) {
for _, event := range events {
if !event.Location.HasGeo() {
continue
}
event.UpcomingNear = make([]*Event, 0, count)
for _, candidate := range upcomingEvents {
if candidate == event || candidate.Cancelled || !candidate.Location.HasGeo() {
continue
}
if distanceKM, _ := utils.DistanceBearing(event.Location.Lat, event.Location.Lon, candidate.Location.Lat, candidate.Location.Lon); distanceKM > maxDistanceKM {
continue
}
event.UpcomingNear = append(event.UpcomingNear, candidate)
if len(event.UpcomingNear) >= count {
break
}
}
}
}

func splitEvents(events []*Event) ([]*Event, []*Event) {
futureEvents := make([]*Event, 0)
pastEvents := make([]*Event, 0)
Expand Down Expand Up @@ -1306,6 +1332,8 @@ func main() {
findPrevNextEvents(events)
events, events_old = splitEvents(events)
events = addMonthSeparators(events)
findUpcomingNearEvents(events, events, 5.0, 3)
findUpcomingNearEvents(events_old, events, 5.0, 3)
events_old = reverse(events_old)
events_old = addMonthSeparatorsDescending(events_old)
tags, tagsList := collectTags(tagDescriptions, events, events_old, groups, shops)
Expand Down
10 changes: 10 additions & 0 deletions templates/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ <h1 class="title">{{.Event.Name}}</h1>
</td>
</tr>
{{end}}
{{if .Event.UpcomingNear}}
<tr>
<th>In der Nähe</th>
<td class="is-w100">
<ul>
{{range .Event.UpcomingNear}}<li><a href="/{{.Slug}}">{{.Name}} ({{.Time}} @ {{.Location.Name}})</a></li>{{end}}
</ul>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
Expand Down
1 change: 1 addition & 0 deletions templates/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2 id="kontakt2">Kontaktmöglichkeiten</h2>

<h2>Letzte Änderungen</h2>
<ul>
<li>2024-04-17: Auf jeder Event-Seite: Hinweis auf zukünftige Laufevents in der Nähe</li>
<li>2024-03-25: Aktualisierung auf <a href="https://bulma.io/" target="_blank">Bulma 1.0.0</a></li>
<li>2024-01-19: <a class="modal-trigger" data-target="support-modal">Support-Dialog</a> hinzugefügt</li>
<li>2024-01-16: privacy-freundliche Webstatistik via <a href="https://www.goatcounter.com/" target="_blank">GoatCounter</a>; keine Cookies, kein Tracking, völlig anonym, DSGVO-konform</li>
Expand Down

0 comments on commit 3532a1b

Please sign in to comment.