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");
|
||||
|
||||
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[]> {
|
||||
return await fs.readdir(path.join(EVENTS_PATH, year));
|
||||
}
|
||||
|
@ -33,7 +55,7 @@ export async function getEventBySlug(
|
|||
slug: string
|
||||
): Promise<Event> {
|
||||
const raw = await fs.readFile(
|
||||
path.join(EVENTS_PATH, year, term, `${slug}.event.md`),
|
||||
path.join(EVENTS_PATH, year, term, `${slug}.md`),
|
||||
"utf-8"
|
||||
);
|
||||
const { content, data: metadata } = matter(raw);
|
||||
|
@ -47,13 +69,8 @@ export async function getEventBySlug(
|
|||
export async function getEventsByTerm(
|
||||
year: string,
|
||||
term: string
|
||||
): Promise<Event[]> {
|
||||
const files = (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
||||
): Promise<string[]> {
|
||||
return (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
||||
.filter((name) => name.endsWith(".md"))
|
||||
.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