Skip to content

Commit 929c47f

Browse files
committed
Add RSS route
1 parent 552a95e commit 929c47f

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import RSS from "rss"
2+
3+
import { getAllEvents } from "../get-all-events"
4+
5+
export const dynamic = "force-static"
6+
export const config = { runtime: "edge" }
7+
8+
export async function GET() {
9+
const { upcomingEvents, pastEvents } = await getAllEvents()
10+
11+
const allEvents = [...upcomingEvents, ...pastEvents]
12+
13+
const feed = new RSS({
14+
title: "GraphQL Community Events & Meetups",
15+
description:
16+
"Stay updated with the latest GraphQL community events and meetups.",
17+
feed_url: "https://the-guild.dev/graphql/community/events/feed.xml",
18+
site_url: "https://the-guild.dev/graphql/community/events",
19+
})
20+
21+
for (const event of allEvents) {
22+
if ("node" in event) {
23+
let date: Date
24+
if (event.node.next && new Date(event.node.next) > new Date()) {
25+
date = new Date(event.node.next)
26+
} else {
27+
date = new Date(event.node.prev)
28+
}
29+
30+
feed.item({
31+
title: event.node.name,
32+
date,
33+
url: event.node.link,
34+
description: "",
35+
lat: event.node.latitude,
36+
long: event.node.longitude,
37+
})
38+
} else if ("start" in event) {
39+
feed.item({
40+
title: event.summary || "GraphQL Working Group",
41+
date: event.start,
42+
url: event.htmlLink,
43+
description: event.description || "",
44+
})
45+
} else {
46+
feed.item({
47+
title: event.name,
48+
date: event.date,
49+
url: event.eventLink,
50+
description: `Host: ${event.host} | Location: ${event.location}`,
51+
})
52+
}
53+
}
54+
55+
return new Response(feed.xml({ indent: true }), {
56+
headers: {
57+
"Content-Type": "application/xml; charset=utf-8",
58+
},
59+
})
60+
}

src/app/(main)/community/events/get-all-events.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@ const WORKING_GROUP_MEETINGS_FILE = join(
1717
export async function getAllEvents() {
1818
const workingGroupMeetings = await loadWorkingGroupMeetings()
1919

20-
let {
21-
pastEvents,
22-
upcomingEvents,
23-
}: { pastEvents: AnyEvent[]; upcomingEvents: AnyEvent[] } = events.reduce(
24-
(acc, event) => {
25-
const now = new Date()
26-
const date = new Date(event.date)
27-
if (date < now) {
28-
acc.pastEvents.push(event)
29-
} else {
30-
acc.upcomingEvents.push(event)
31-
}
32-
return acc
33-
},
34-
{ pastEvents: [], upcomingEvents: [] } as {
35-
pastEvents: Event[]
36-
upcomingEvents: Event[]
37-
},
38-
)
20+
let pastEvents: AnyEvent[] = []
21+
let upcomingEvents: AnyEvent[] = []
3922

4023
const now = new Date()
4124

25+
for (const event of events) {
26+
const date = new Date(event.date)
27+
if (date < now) {
28+
pastEvents.push(event)
29+
} else {
30+
upcomingEvents.push(event)
31+
}
32+
}
33+
4234
for (const meeting of workingGroupMeetings) {
4335
if (meeting.start && new Date(meeting.start) < now) {
4436
pastEvents.push(meeting)

0 commit comments

Comments
 (0)