diff --git a/lib/helpers/mdx/recma.ts b/lib/helpers/mdx/recma.ts new file mode 100644 index 00000000..3a6bd471 --- /dev/null +++ b/lib/helpers/mdx/recma.ts @@ -0,0 +1 @@ +export { default as recmaMdxEscapeMissingComponents } from "recma-mdx-escape-missing-components"; diff --git a/lib/helpers/mdx/rehype.ts b/lib/helpers/mdx/rehype.ts new file mode 100644 index 00000000..ce28d96c --- /dev/null +++ b/lib/helpers/mdx/rehype.ts @@ -0,0 +1,4 @@ +export { default as rehypeMdxImportMedia } from "rehype-mdx-import-media"; +export { default as rehypePrettyCode } from "rehype-pretty-code"; +export { default as rehypeSlug } from "rehype-slug"; +export { default as rehypeUnwrapImages } from "rehype-unwrap-images"; diff --git a/lib/helpers/remark-rehype-plugins.ts b/lib/helpers/mdx/remark.ts similarity index 58% rename from lib/helpers/remark-rehype-plugins.ts rename to lib/helpers/mdx/remark.ts index 119592f5..68461ec9 100644 --- a/lib/helpers/remark-rehype-plugins.ts +++ b/lib/helpers/mdx/remark.ts @@ -1,7 +1,3 @@ -export { default as rehypeMdxImportMedia } from "rehype-mdx-import-media"; -export { default as rehypePrettyCode } from "rehype-pretty-code"; -export { default as rehypeSlug } from "rehype-slug"; -export { default as rehypeUnwrapImages } from "rehype-unwrap-images"; export { default as remarkFrontmatter } from "remark-frontmatter"; export { default as remarkGfm } from "remark-gfm"; export { default as remarkHtml } from "remark-html"; diff --git a/lib/helpers/posts.ts b/lib/helpers/posts.ts index a3665359..c0c8ae24 100644 --- a/lib/helpers/posts.ts +++ b/lib/helpers/posts.ts @@ -4,7 +4,7 @@ import path from "path"; import fs from "fs/promises"; import glob from "fast-glob"; import { unified } from "unified"; -import { remarkHtml, remarkParse, remarkSmartypants, remarkFrontmatter } from "./remark-rehype-plugins"; +import { remarkHtml, remarkParse, remarkSmartypants, remarkFrontmatter } from "./mdx/remark"; import { decode } from "html-entities"; import { POSTS_DIR } from "../config/constants"; @@ -106,7 +106,6 @@ export const getFrontMatter: { /** Returns the content of a post with very limited processing to include in RSS feeds */ export const getContent = cache(async (slug: string): Promise => { try { - // TODO: also remove MDX-related syntax (e.g. import/export statements) const content = await unified() .use(remarkParse) .use(remarkFrontmatter) @@ -137,7 +136,7 @@ export const getContent = cache(async (slug: string): Promise

", "").trim(); + return content.toString().replaceAll("

\n", "").replaceAll("

{/* prettier-ignore */}

\n", "").trim(); } catch (error) { console.error(`Failed to load/parse content for post with slug "${slug}":`, error); return undefined; diff --git a/next.config.ts b/next.config.ts index 4f646295..5bdca239 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,13 +1,13 @@ -/* eslint-disable @typescript-eslint/no-require-imports, import/no-anonymous-default-export */ - -import * as mdxPlugins from "./lib/helpers/remark-rehype-plugins"; +import * as remarkPlugins from "./lib/helpers/mdx/remark"; +import * as rehypePlugins from "./lib/helpers/mdx/rehype"; +import * as recmaPlugins from "./lib/helpers/mdx/recma"; import type { NextConfig } from "next"; // check environment variables at build time // https://env.t3.gg/docs/nextjs#validate-schema-on-build-(recommended) import "./lib/env"; -const nextConfig: NextConfig = { +const nextConfig = { reactStrictMode: true, pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"], eslint: { @@ -140,29 +140,32 @@ const nextConfig: NextConfig = { permanent: true, }, ], -}; +} satisfies NextConfig; // my own macgyvered version of next-compose-plugins (RIP) const nextPlugins: Array< // eslint-disable-next-line @typescript-eslint/no-explicit-any (config: NextConfig) => NextConfig | [(config: NextConfig) => NextConfig, any] > = [ + // eslint-disable-next-line @typescript-eslint/no-require-imports require("@next/bundle-analyzer")({ enabled: !!process.env.ANALYZE, }), + // eslint-disable-next-line @typescript-eslint/no-require-imports require("@next/mdx")({ options: { + recmaPlugins: [recmaPlugins.recmaMdxEscapeMissingComponents], remarkPlugins: [ - mdxPlugins.remarkFrontmatter, - mdxPlugins.remarkMdxFrontmatter, - mdxPlugins.remarkGfm, - mdxPlugins.remarkSmartypants, + remarkPlugins.remarkFrontmatter, + remarkPlugins.remarkMdxFrontmatter, + remarkPlugins.remarkGfm, + remarkPlugins.remarkSmartypants, ], rehypePlugins: [ - mdxPlugins.rehypeUnwrapImages, - mdxPlugins.rehypeSlug, + rehypePlugins.rehypeUnwrapImages, + rehypePlugins.rehypeSlug, [ - mdxPlugins.rehypePrettyCode, + rehypePlugins.rehypePrettyCode, { theme: { light: "material-theme-lighter", @@ -174,11 +177,12 @@ const nextPlugins: Array< keepBackground: false, }, ], - mdxPlugins.rehypeMdxImportMedia, + rehypePlugins.rehypeMdxImportMedia, ], }, }), ]; +// eslint-disable-next-line import/no-anonymous-default-export export default (): NextConfig => nextPlugins.reduce((acc, plugin) => (Array.isArray(plugin) ? plugin[0](acc, plugin[1]) : plugin(acc)), nextConfig); diff --git a/notes/dropping-dropbox/index.mdx b/notes/dropping-dropbox/index.mdx index 05230102..a7166382 100644 --- a/notes/dropping-dropbox/index.mdx +++ b/notes/dropping-dropbox/index.mdx @@ -31,7 +31,7 @@ Decisions made by the top folks at Dropbox gave me an increasingly sour taste in - Explicitly [dropping support for symlinking](https://news.ycombinator.com/item?id=20844363) (aka making aliases to) files outside of the literal `~/Dropbox` folder, which was incredibly helpful for nerds — once their main audience and biggest cheerleaders — with things like [dotfiles](https://github.com/jakejarvis/dotfiles) and Git repositories. - ...and as a bonus, making the process of canceling Dropbox Pro incredibly convoluted, annoying, and sketchy. Here's a video demonstration via [Justin Dunham](https://twitter.com/jwyattd): - diff --git a/notes/presidential-candidates-404-pages/index.mdx b/notes/presidential-candidates-404-pages/index.mdx index 11908792..c726dbf3 100644 --- a/notes/presidential-candidates-404-pages/index.mdx +++ b/notes/presidential-candidates-404-pages/index.mdx @@ -27,7 +27,7 @@ I'm a _huge_ sucker for Kate McKinnon's spot-on impression of Warren on Saturday Although the designer who selected this GIF likely had _thousands_ of choices when searching "[Bernie finger wagging GIF](https://www.google.com/search?q=Bernie+finger+wagging+GIF&tbm=isch&tbs=itp:animated)," the text beside it is well-written and funny — even though we both know putting a page at [berniesanders.com/zxcliaosid](https://berniesanders.com/zxcliaosid/) probably won't be a top priority of a President Sanders. -