Add helper functions for fetching events #115

Merged
j285he merged 13 commits from feat/events-lib into main 1 year ago
j285he commented 2 years ago
Collaborator

helper functions for [year] and [year]/[term] only

closes #110

helper functions for [year] and [year]/[term] only closes #110
j285he added 1 commit 2 years ago
b733acd156 Add lib file
a3thakra changed title from Add lib file to Add helper functions for fetching events 2 years ago
j285he added 1 commit 2 years ago
bfcbf5c687 Fix type error
a3thakra reviewed 2 years ago
lib/events.ts Outdated
const EVENTS_PATH = path.join("content", "events");
export async function getYears(): Promise<string[]> {
return await fs.readdir(EVENTS_PATH);
Collaborator

You should use options.withFileTypes here and only return the items that are directories

You should use `options.withFileTypes` here and only return the items that are directories
Collaborator
More info here: https://nodejs.org/api/fs.html#fs_fspromises_readdir_path_options
j285he marked this conversation as resolved
a3thakra reviewed 2 years ago
lib/events.ts Outdated
}
export async function getTermsByYear(year: string): Promise<string[]> {
return await fs.readdir(path.join(EVENTS_PATH, year));
Collaborator

same here

same here
j285he marked this conversation as resolved
a3thakra reviewed 2 years ago
lib/events.ts Outdated
): 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));
Collaborator

Can we switch to foo.md instead of foo.event.md?

Can we switch to `foo.md` instead of `foo.event.md`?
Collaborator

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.

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.
j285he marked this conversation as resolved
a3thakra reviewed 2 years ago
};
}
export async function getEventsByTerm(
Collaborator

imo this function should just return event slugs, and not the complete events.

imo this function should just return event slugs, and not the complete events.
j285he marked this conversation as resolved
j285he added 1 commit 2 years ago
9f7d40b426 Merge branch 'main' into feat/events-lib
j285he added 3 commits 2 years ago
a3thakra reviewed 2 years ago
lib/events.ts Outdated
export async function getYears(): Promise<string[]> {
return (await fs.readdir(EVENTS_PATH, { withFileTypes: true })).map(
(dirent) => dirent.name
);
Collaborator

We are missing something here ... read the documentation for withFileTypes a bit more carefully. What does it return? What do we want to return?

We are missing something here ... read the documentation for `withFileTypes` a bit more carefully. What does it return? What do we want to return?
j285he marked this conversation as resolved
a3thakra reviewed 2 years ago
lib/events.ts Outdated
): Promise<string[]> {
return (
await fs.readdir(path.join(EVENTS_PATH, year, term), {
withFileTypes: true,
Collaborator

there is no need for doing this here

there is no need for doing this here
j285he marked this conversation as resolved
j285he added 1 commit 1 year ago
590b2554c0 Fixes for dirents
j285he added 1 commit 1 year ago
d237621d14 ESLint fixes
Collaborator

Terms and years should be sorted. Take a look at #145

Terms and years should be sorted. Take a look at #145
j285he added 1 commit 1 year ago
3a697c09c0 Add sorting
Poster
Collaborator

Terms and years should be sorted. Take a look at #145

Why do we have the order as winter, spring, then fall?

> Terms and years should be sorted. Take a look at #145 Why do we have the order as winter, spring, then fall?
j285he added 2 commits 1 year ago
j285he added 1 commit 1 year ago
b32fd53d95 Remove unneeded dirent conversion
Collaborator

Why do we have the order as winter, spring, then fall?

because that's the chronological order. Jan - April, May -> August, Sept -> Dec

> Why do we have the order as winter, spring, then fall? because that's the chronological order. Jan - April, May -> August, Sept -> Dec
j285he added 1 commit 1 year ago
fecd3bf3e0 Rename functions
a3thakra approved these changes 1 year ago
j285he merged commit 64fbabf204 into main 1 year ago
j285he deleted branch feat/events-lib 1 year ago

Reviewers

a3thakra approved these changes 1 year ago
continuous-integration/drone/push Build is passing
The pull request has been merged as 64fbabf204.
Sign in to join this conversation.
No reviewers
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…
There is no content yet.