
2023 Blog Refresh
NNazhoir
Published on November 19, 2023 (1y ago)I updated my blog this weekend and wanted to share some thoughts along the way:
Content Management
I've moved my content from HTML to vanilla Markdown, to MDX, to a CMS, and back to MDX over the years. My content requirements as of now are:
- Written in Markdown¹
- Support for syntax highlighting, embedded tweets, and other components
- Managed through version control²
- Minimal external dependencies
My goal was to simplify without giving up too many features.
Retrieving Content
You can go surprisingly far with just Node.js and JavaScript. You'll notice a theme start to emerge in this blog post: fewer dependencies, and more copy/paste-able code.
I removed the following libraries:
contentlayer
next-contentlayer
rehype-autolink-headings
rehype-pretty-code
rehype-slug
remark-gfm
shiki
import fs from 'fs';
import path from 'path';
function getMDXFiles(dir) {
return fs.readdirSync(dir).filter((file) => path.extname(file) === '.mdx');
}
function readMDXFile(filePath) {
let rawContent = fs.readFileSync(filePath, 'utf-8');
return parseFrontmatter(rawContent);
}
function getMDXData(dir) {
let mdxFiles = getMDXFiles(dir);
return mdxFiles.map((file) => {
let { metadata, content } = readMDXFile(path.join(dir, file));
let slug = path.basename(file, path.extname(file));
return {
metadata,
slug,
content,
};
});
}
export function getBlogPosts() {
return getMDXData(path.join(process.cwd(), 'content'));
}