directly (and still dynamically) assign a few of the mdx components

This commit is contained in:
2022-01-05 15:07:54 -05:00
parent fb491d7337
commit 2d44b58242
9 changed files with 43 additions and 44 deletions
+1
View File
@@ -1,3 +1,4 @@
// do not convert to ESM -- this needs to be imported in CJS files like next.config.js too
module.exports = {
// Site info
siteName: "Jake Jarvis",
+3 -2
View File
@@ -3,6 +3,7 @@ import path from "path";
import matter from "gray-matter";
import { NOTES_DIR, baseUrl } from "./config";
// returns front matter and/or *raw* markdown contents of a given slug
export const getNoteData = (slug: string) => {
const fullPath = path.join(process.cwd(), NOTES_DIR, `${slug}.mdx`);
const rawContent = fs.readFileSync(fullPath, "utf8");
@@ -19,15 +20,15 @@ export const getNoteData = (slug: string) => {
};
};
// all .mdx files in NOTES_DIR
// returns all .mdx files in NOTES_DIR (without .mdx extension)
export const getNoteSlugs = () =>
fs
.readdirSync(path.join(process.cwd(), NOTES_DIR))
.filter((file) => /\.mdx$/.test(file))
.map((noteFile) => noteFile.replace(/\.mdx$/, ""));
// returns the front matter of ALL notes, sorted reverse chronologically
export const getAllNotes = () =>
getNoteSlugs()
.map((slug) => getNoteData(slug).frontMatter)
// sort notes by date in descending order
.sort((note1: any, note2: any) => (note1.date > note2.date ? -1 : 1));