@@ -40,21 +40,36 @@ import dayjs from "dayjs";
4040import TiltedCard from " @/components/TiltedCard" ;
4141import { lunalink } from " @bearstudio/lunalink" ;
4242import { ROUTES } from " @/routes.gen" ;
43+ import RelatedEvents from " @/components/RelatedEvents/index.astro" ;
4344
4445export 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
5974const partners = await getEntries (event .data .partners ?? []);
6075const speakers = await getEntries (event .data ._computed .speakers ?? []);
@@ -64,7 +79,6 @@ const coOrganizers = (await getEntries(event.data.coOrganizers ?? [])).filter(
6479const sponsors = await getEntries (
6580 (event .data .sponsors ?? []).map ((s ) => s .slug ),
6681);
67-
6882const navItems = await getEventNavItems (event .id );
6983
7084const { 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