Add helper functions for fetching events #115
Merged
j285he
merged 13 commits from feat/events-lib
into main
2 years ago
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'feat/events-lib'
Deleting a branch is permanent. It CANNOT be undone. Continue?
helper functions for [year] and [year]/[term] only
closes #110
Add lib fileto Add helper functions for fetching events 2 years agoconst EVENTS_PATH = path.join("content", "events");
export async function getYears(): Promise<string[]> {
return await fs.readdir(EVENTS_PATH);
You should use
options.withFileTypes
here and only return the items that are directoriesMore info here: https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options
}
export async function getTermsByYear(year: string): Promise<string[]> {
return await fs.readdir(path.join(EVENTS_PATH, year));
same here
): Promise<Event[]> {
const files = (await fs.readdir(path.join(EVENTS_PATH, year, term)))
.filter((name) => name.endsWith(".event.md"))
.map((name) => name.slice(0, -".event.md".length));
Can we switch to
foo.md
instead offoo.event.md
?We were using
.event.mdx
because that enabled us to easily cast the type of the file to what we wanted. But we can't really do that here.};
}
export async function getEventsByTerm(
imo this function should just return event slugs, and not the complete events.
export async function getYears(): Promise<string[]> {
return (await fs.readdir(EVENTS_PATH, { withFileTypes: true })).map(
(dirent) => dirent.name
);
We are missing something here ... read the documentation for
withFileTypes
a bit more carefully. What does it return? What do we want to return?): Promise<string[]> {
return (
await fs.readdir(path.join(EVENTS_PATH, year, term), {
withFileTypes: true,
there is no need for doing this here
Terms and years should be sorted. Take a look at #145
Why do we have the order as winter, spring, then fall?
because that's the chronological order. Jan - April, May -> August, Sept -> Dec
64fbabf204
into main 2 years agoReviewers
64fbabf204
.