2021-07-27 16:45:19 -04:00
|
|
|
import fs from "fs/promises";
|
|
|
|
import path from "path";
|
|
|
|
import matter from "gray-matter";
|
|
|
|
import { serialize } from "next-mdx-remote/serialize";
|
|
|
|
import { MDXRemoteSerializeResult } from "next-mdx-remote";
|
|
|
|
|
|
|
|
const EVENTS_PATH = path.join("content", "events");
|
|
|
|
|
|
|
|
export async function getYears(): Promise<string[]> {
|
2021-08-02 22:36:06 -04:00
|
|
|
return (await fs.readdir(EVENTS_PATH, { withFileTypes: true })).map(
|
|
|
|
(dirent) => dirent.name
|
|
|
|
);
|
2021-07-27 16:45:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getTermsByYear(year: string): Promise<string[]> {
|
2021-08-02 22:36:06 -04:00
|
|
|
return (
|
|
|
|
await fs.readdir(path.join(EVENTS_PATH, year), {
|
|
|
|
withFileTypes: true,
|
|
|
|
})
|
|
|
|
).map((dirent) => dirent.name);
|
2021-07-27 16:45:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Metadata {
|
|
|
|
name: string;
|
|
|
|
short: string;
|
|
|
|
date: string;
|
|
|
|
online: boolean;
|
|
|
|
location: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Event {
|
2021-07-27 20:33:53 -04:00
|
|
|
content: MDXRemoteSerializeResult<Record<string, unknown>>;
|
2021-07-27 16:45:19 -04:00
|
|
|
metadata: Metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getEventBySlug(
|
|
|
|
year: string,
|
|
|
|
term: string,
|
2021-07-27 20:33:53 -04:00
|
|
|
slug: string
|
2021-07-27 16:45:19 -04:00
|
|
|
): Promise<Event> {
|
|
|
|
const raw = await fs.readFile(
|
2021-08-02 22:17:36 -04:00
|
|
|
path.join(EVENTS_PATH, year, term, `${slug}.md`),
|
2021-07-27 16:45:19 -04:00
|
|
|
"utf-8"
|
|
|
|
);
|
|
|
|
const { content, data: metadata } = matter(raw);
|
|
|
|
|
|
|
|
return {
|
2021-07-27 20:33:53 -04:00
|
|
|
content: await serialize(content),
|
2021-07-27 16:45:19 -04:00
|
|
|
metadata: metadata as Metadata,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getEventsByTerm(
|
|
|
|
year: string,
|
|
|
|
term: string
|
2021-08-02 22:17:36 -04:00
|
|
|
): Promise<string[]> {
|
2021-08-02 22:36:06 -04:00
|
|
|
return (
|
|
|
|
await fs.readdir(path.join(EVENTS_PATH, year, term), {
|
|
|
|
withFileTypes: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.map((dirent) => dirent.name)
|
2021-08-02 21:01:36 -04:00
|
|
|
.filter((name) => name.endsWith(".md"))
|
|
|
|
.map((name) => name.slice(0, -".md".length));
|
2021-07-27 16:45:19 -04:00
|
|
|
}
|