1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-19 13:55:31 -04:00

restore YAML frontmatter

This commit is contained in:
2025-03-16 15:35:01 -04:00
parent 99ec01de0a
commit 2b4a86a900
27 changed files with 385 additions and 193 deletions

View File

@@ -1,7 +1,6 @@
import { cache } from "react";
import path from "path";
import glob from "fast-glob";
import pMap from "p-map";
import pMemoize from "p-memoize";
import { decode } from "html-entities";
import { formatDate } from "./format-date";
import { BASE_URL, POSTS_DIR } from "../config/constants";
@@ -71,7 +70,8 @@ export const getFrontMatter = async (slug: string): Promise<FrontMatter> => {
};
};
export const getPostSlugs = pMemoize(async (): Promise<string[]> => {
// use filesystem to get a simple list of all post slugs
export const getPostSlugs = cache(async (): Promise<string[]> => {
// list all .mdx files in POSTS_DIR
const mdxFiles = await glob("**/*.mdx", {
cwd: path.join(process.cwd(), POSTS_DIR),
@@ -85,9 +85,10 @@ export const getPostSlugs = pMemoize(async (): Promise<string[]> => {
});
// returns the parsed front matter of ALL posts, sorted reverse chronologically
export const getAllPosts = pMemoize(async (): Promise<FrontMatter[]> => {
// for each post, query its front matter
const data = await pMap(await getPostSlugs(), async (slug) => await getFrontMatter(slug));
export const getAllPosts = cache(async (): Promise<FrontMatter[]> => {
// concurrently fetch the front matter of each post
const slugs = await getPostSlugs();
const data = await Promise.all(slugs.map(async (slug) => await getFrontMatter(slug)));
// sort the results by date
data.sort((post1, post2) => (post1.date > post2.date ? -1 : 1));

View File

@@ -4,7 +4,9 @@ export { default as rehypeSanitize } from "rehype-sanitize";
export { default as rehypeSlug } from "rehype-slug";
export { default as rehypeStringify } from "rehype-stringify";
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 remarkMdxFrontmatter } from "remark-mdx-frontmatter";
export { default as remarkParse } from "remark-parse";
export { default as remarkRehype } from "remark-rehype";
export { default as remarkSmartypants } from "remark-smartypants";