1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-17 18:45:32 -04:00

Migrate to app router (#2254)

This commit is contained in:
2025-02-07 11:33:38 -05:00
committed by GitHub
parent e97613dda5
commit 8aabb4a66f
179 changed files with 4095 additions and 4951 deletions

View File

@@ -1,13 +1,12 @@
import path from "path";
import fs from "fs/promises";
import { serialize } from "next-mdx-remote/serialize";
import glob from "fast-glob";
import pMap from "p-map";
import pMemoize from "p-memoize";
import matter from "gray-matter";
import { formatDate } from "./format-date";
import { minifier } from "./minifier";
import type { PostFrontMatter, PostWithSource } from "../../types";
import type { PostFrontMatter } from "../../types";
import { metadata as defaultMetadata } from "../../app/layout";
// path to directory with .mdx files, relative to project root
export const POSTS_DIR = "notes";
@@ -60,49 +59,14 @@ export const getPostData = async (
title,
htmlTitle,
slug,
permalink: `${process.env.NEXT_PUBLIC_BASE_URL || ""}/${POSTS_DIR}/${slug}/`,
date: formatDate(data.date), // validate/normalize the date string provided from front matter
permalink: new URL(`/${POSTS_DIR}/${slug}/`, defaultMetadata.metadataBase || "").href,
image: data.image ? new URL(data.image, defaultMetadata.metadataBase || "").href : undefined,
},
markdown: content,
};
};
// fully parses MDX into JS and returns *everything* about a post
export const compilePost = async (slug: string): Promise<PostWithSource> => {
const { remarkGfm, remarkSmartypants, rehypeSlug, rehypeUnwrapImages, rehypePrism } = await import(
"./remark-rehype-plugins"
);
const { frontMatter, markdown } = await getPostData(slug);
const { compiledSource } = await serialize(markdown, {
parseFrontmatter: false,
mdxOptions: {
remarkPlugins: [
[remarkGfm, { singleTilde: false }],
[
remarkSmartypants,
{
quotes: true,
dashes: "oldschool",
backticks: false,
ellipses: false,
},
],
],
rehypePlugins: [rehypeSlug, rehypeUnwrapImages, [rehypePrism, { ignoreMissing: true }]],
},
});
return {
frontMatter,
source: {
// save some bytes
compiledSource: minifier(compiledSource),
},
};
};
export const getPostSlugs = pMemoize(async (): Promise<string[]> => {
// list all .mdx files in POSTS_DIR
const mdxFiles = await glob("*.mdx", {