Change event file names
This commit is contained in:
parent
f7e878d3f8
commit
4239131512
|
@ -7,9 +7,31 @@ import { MDXRemoteSerializeResult } from "next-mdx-remote";
|
||||||
const EVENTS_PATH = path.join("content", "events");
|
const EVENTS_PATH = path.join("content", "events");
|
||||||
|
|
||||||
export async function getYears(): Promise<string[]> {
|
export async function getYears(): Promise<string[]> {
|
||||||
return await fs.readdir(EVENTS_PATH);
|
//return await fs.readdir(EVENTS_PATH, { withFileTypes: true }, (err, files)=>err ? console.log(err));
|
||||||
|
// return await fs.readdir(
|
||||||
|
// __dirname,
|
||||||
|
// { withFileTypes: true },
|
||||||
|
// (err: Error, files: string[]) => {
|
||||||
|
// if (err) console.log(err);
|
||||||
|
// else {
|
||||||
|
// files.forEach((file) => {
|
||||||
|
// console.log(file);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs.readdir(__dirname, { withFileTypes: true }, (err, files) => {
|
||||||
|
console.log("\nCurrent directory files:");
|
||||||
|
if (err) console.log(err);
|
||||||
|
else {
|
||||||
|
files.forEach((file) => {
|
||||||
|
console.log(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export async function getTermsByYear(year: string): Promise<string[]> {
|
export async function getTermsByYear(year: string): Promise<string[]> {
|
||||||
return await fs.readdir(path.join(EVENTS_PATH, year));
|
return await fs.readdir(path.join(EVENTS_PATH, year));
|
||||||
}
|
}
|
||||||
|
@ -33,7 +55,7 @@ export async function getEventBySlug(
|
||||||
slug: string
|
slug: string
|
||||||
): Promise<Event> {
|
): Promise<Event> {
|
||||||
const raw = await fs.readFile(
|
const raw = await fs.readFile(
|
||||||
path.join(EVENTS_PATH, year, term, `${slug}.event.md`),
|
path.join(EVENTS_PATH, year, term, `${slug}.md`),
|
||||||
"utf-8"
|
"utf-8"
|
||||||
);
|
);
|
||||||
const { content, data: metadata } = matter(raw);
|
const { content, data: metadata } = matter(raw);
|
||||||
|
@ -47,13 +69,8 @@ export async function getEventBySlug(
|
||||||
export async function getEventsByTerm(
|
export async function getEventsByTerm(
|
||||||
year: string,
|
year: string,
|
||||||
term: string
|
term: string
|
||||||
): Promise<Event[]> {
|
): Promise<string[]> {
|
||||||
const files = (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
return (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
||||||
.filter((name) => name.endsWith(".md"))
|
.filter((name) => name.endsWith(".md"))
|
||||||
.map((name) => name.slice(0, -".md".length));
|
.map((name) => name.slice(0, -".md".length));
|
||||||
|
|
||||||
const props = await Promise.all(
|
|
||||||
files.map((file) => getEventBySlug(year, term, file))
|
|
||||||
);
|
|
||||||
return props;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue