Add book, engineering, and writing content handling with MDX support

This commit is contained in:
2026-02-01 19:40:55 +03:00
parent 634281b3f4
commit 72f7063314
4 changed files with 134 additions and 13 deletions
+11 -13
View File
@@ -5,7 +5,7 @@ import remarkGfm from "remark-gfm";
export interface Content<TMetadata = { [key: string]: any }> {
metadata: TMetadata;
content: string;
source: string;
}
export type MaybeContent<TMetadata> = Content<TMetadata> | undefined;
@@ -14,29 +14,27 @@ export async function getMdxContent<TMetadata>(
...paths: string[]
): Promise<MaybeContent<TMetadata>> {
const contentPath = path.join(process.cwd(), "content", ...paths);
if (!fs.existsSync(contentPath)) {
return undefined;
}
const content = fs.readFileSync(contentPath, "utf-8");
const content = fs.readFileSync(contentPath, "utf8");
const source = await serialize(content, {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins: [remarkGfm],
development: false,
remarkPlugins: [remarkGfm],
},
});
// Remove the ugly footnotes heading from react-gfm
const footnotes =
/_jsx\(_components.h2, {.*?children: "Footnotes".*?}\), "\\n", /gs;
const hr = ``;
const compiledSource = source.compiledSource.replaceAll(footnotes, hr);
const footnotes = /_jsx\(_components.h2, {.*?children: "Footnotes".*?}\), "\\n", /gs;
const hr = ``
const compiledSource = source.compiledSource.replace(footnotes, hr);
return{
return {
metadata: source.frontmatter as TMetadata,
content: compiledSource,
}
source: compiledSource,
};
}