Add helper functions for fetching events #115
No reviewers
Labels
No Label
a11y
Backlog
Blocked
Bug
Content
Dependencies
Design
Feature Request
Good First Issue
In Progress
Performance
Priority - High
Priority - Low
Priority - Medium
Untriaged
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: www/www-new#115
Loading…
Reference in New Issue
No description provided.
Delete Branch "feat/events-lib"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
helper functions for [year] and [year]/[term] only
closes #110
Add lib fileto Add helper functions for fetching events@ -0,0 +7,4 @@
const 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
@ -0,0 +11,4 @@
}
export async function getTermsByYear(year: string): Promise<string[]> {
return await fs.readdir(path.join(EVENTS_PATH, year));
same here
@ -0,0 +50,4 @@
): 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.@ -0,0 +44,4 @@
};
}
export async function getEventsByTerm(
imo this function should just return event slugs, and not the complete events.
@ -0,0 +9,4 @@
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?@ -0,0 +56,4 @@
): 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