Dynamically generate event calendar #332

Merged
a3thakra merged 25 commits from adi-ical into main 2021-09-27 16:20:20 -04:00
1 changed files with 33 additions and 27 deletions
Showing only changes of commit 406aee9d11 - Show all commits

View File

@ -1,35 +1,41 @@
import { writeFile } from "fs/promises";
import path from "path";
import { addHours } from "date-fns";
import ical, { ICalCalendarMethod } from "ical-generator";
import { getAllEvents } from "../lib/events";
const calendar = ical({
name: "University of Waterloo Computer Science Club",
method: ICalCalendarMethod.PUBLISH,
scale: "GREGORIAN",
x: { "X-WR-RELCALID": "3359A191-B19E-4B53-BADC-DFC084FC51C9" },
events: [
{
location: "Twitch - Online",
start: new Date(
"Tuesday September 14 2021 19:00:00 GMT-0400 (Eastern Daylight Time)"
),
end: new Date(
"Tuesday September 14 2021 20:00:00 GMT-0400 (Eastern Daylight Time)"
),
description:
"Learn about our plans for the term and play some games with us.",
},
],
});
export async function generateCalendar() {
const events = await getAllEvents();
async function test() {
const start = Date.now();
await getAllEvents();
const finish = Date.now();
const calendar = ical({
name: "University of Waterloo Computer Science Club",
method: ICalCalendarMethod.PUBLISH,
scale: "GREGORIAN",
x: { "X-WR-RELCALID": "3359A191-B19E-4B53-BADC-DFC084FC51C9" },
events: events.reverse().map(({ metadata }) => ({
id: `${new Date(metadata.date)
.toISOString()
.replaceAll("-", "")
.replaceAll(":", "")
.replaceAll(".", "")}@csclub.uwaterloo.ca`,
summary: metadata.name,
description: `${metadata.short} --- Learn more at ${path.join(
"https://csclub.uwaterloo.ca",
process.env.NEXT_PUBLIC_BASE_PATH ?? "/",
metadata.permaLink
)}`,
start: new Date(metadata.date),
end: addHours(new Date(metadata.date), 1),
location: metadata.online
? `Online - ${metadata.location}`
: metadata.location,
organizer: "exec@csclub.uwaterloo.ca",
})),
});
console.log(finish - start);
await writeFile("public/events.ics", calendar.toString());
}
test();
export {};
void generateCalendar();