29 lines
871 B
TypeScript
29 lines
871 B
TypeScript
import { readFile, readdir } from "fs/promises";
|
|
import path from "path";
|
|
import matter from "gray-matter";
|
|
import { serialize } from "next-mdx-remote/serialize";
|
|
|
|
const EXECS_PATH = path.join("content", "meet-the-team", "execs");
|
|
const fileType = ".md";
|
|
|
|
export interface Metadata {
|
|
name: string;
|
|
role: string;
|
|
image?: string; // path to image of person, relative to public directory
|
|
}
|
|
|
|
export async function getExecNames() {
|
|
return (await readdir(EXECS_PATH))
|
|
.filter((name) => name.endsWith(fileType))
|
|
.map((name) => name.slice(0, -1 * fileType.length));
|
|
}
|
|
|
|
export async function getExecContent(fileName: string, convert = true) {
|
|
const raw = await readFile(path.join(EXECS_PATH, `${fileName}${fileType}`));
|
|
const { content, data: metadata } = matter(raw);
|
|
return {
|
|
content: convert ? await serialize(content) : content,
|
|
metadata,
|
|
};
|
|
}
|