Skip to content

Commit 2c9894b

Browse files
committed
feat: add related events section on event page (#207)
1 parent dbfcd33 commit 2c9894b

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
import EventCard from "@/components/EventCard/index.astro";
3+
import TiltedCard from "@/components/TiltedCard";
4+
import type { CollectionEntry } from "astro:content";
5+
6+
interface Props {
7+
currentEvent: CollectionEntry<"events">;
8+
relatedEvents: CollectionEntry<"events">[];
9+
}
10+
11+
const { currentEvent, relatedEvents } = Astro.props;
12+
---
13+
14+
{
15+
relatedEvents.length > 0 && (
16+
<div class="relative mx-auto flex w-full max-w-screen-lg flex-col gap-8 px-4 py-12 md:py-24">
17+
<h2 class="scroll-mt-32 font-heading text-2xl font-medium uppercase tracking-widest">
18+
More Events in {currentEvent.data._computed.city?.data.name}
19+
</h2>
20+
<div class="grid gap-4 md:grid-cols-3">
21+
{relatedEvents.map((event) => (
22+
<TiltedCard client:visible>
23+
<EventCard event={event} />
24+
</TiltedCard>
25+
))}
26+
</div>
27+
</div>
28+
)
29+
}

src/pages/events/[id]/index.astro

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,36 @@ import dayjs from "dayjs";
4040
import TiltedCard from "@/components/TiltedCard";
4141
import { lunalink } from "@bearstudio/lunalink";
4242
import { ROUTES } from "@/routes.gen";
43+
import RelatedEvents from "@/components/RelatedEvents/index.astro";
4344
4445
export async function getStaticPaths() {
45-
const events = await getEventsCollection();
46+
const allEvents = await getEventsCollection();
4647
4748
return Promise.all(
48-
events.map(async (event) => ({
49-
params: { id: event.id },
50-
props: {
51-
event,
52-
},
53-
})),
49+
allEvents.map(async (event) => {
50+
const relatedEvents = allEvents
51+
.filter(
52+
(e) =>
53+
e.id !== event.id &&
54+
e.data._computed.city?.id === event.data._computed.city?.id &&
55+
(dayjs(e.data.date).isAfter(dayjs()) ||
56+
dayjs(e.data.date).isAfter(dayjs().subtract(30, "day"))),
57+
)
58+
.sort((a, b) => dayjs(a.data.date).diff(dayjs(b.data.date)))
59+
.slice(0, 3);
60+
61+
return {
62+
params: { id: event.id },
63+
props: {
64+
event,
65+
relatedEvents,
66+
},
67+
};
68+
}),
5469
);
5570
}
5671
57-
const { event } = Astro.props;
72+
const { event, relatedEvents } = Astro.props;
5873
5974
const partners = await getEntries(event.data.partners ?? []);
6075
const speakers = await getEntries(event.data._computed.speakers ?? []);
@@ -64,7 +79,6 @@ const coOrganizers = (await getEntries(event.data.coOrganizers ?? [])).filter(
6479
const sponsors = await getEntries(
6580
(event.data.sponsors ?? []).map((s) => s.slug),
6681
);
67-
6882
const navItems = await getEventNavItems(event.id);
6983
7084
const { Content } = await render(event);
@@ -646,6 +660,8 @@ const ctaEventMetadata = {
646660
</a>
647661
</div>
648662

663+
<RelatedEvents currentEvent={event} relatedEvents={relatedEvents} />
664+
649665
<div class="py-8 md:py-12">
650666
<JoinTheCommunity />
651667
</div>

0 commit comments

Comments
 (0)