1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-09-17 16:35:31 -04:00

edge functions didn't make sense for database calls

This commit is contained in:
2023-10-08 21:38:09 -04:00
parent 23844c6843
commit 179ee92f6c
11 changed files with 203 additions and 239 deletions

View File

@@ -2,18 +2,16 @@ import { serialize } from "next-mdx-remote/serialize";
import { minify } from "uglify-js";
import { getNoteData } from "./parse-notes";
// remark/rehype markdown plugins
import remarkGfm from "remark-gfm";
import remarkSmartypants from "remark-smartypants";
import remarkUnwrapImages from "remark-unwrap-images";
import rehypeSlug from "rehype-slug";
import rehypePrism from "rehype-prism-plus";
import type { NoteWithSource } from "../../types";
// fully parses MDX into JS and returns *everything* about a note
export const compileNote = async (slug: string): Promise<NoteWithSource> => {
const { frontMatter, content } = await getNoteData(slug);
const { remarkGfm, remarkSmartypants, remarkUnwrapImages, rehypeSlug, rehypePrism } = await import(
"./remark-rehype-plugins"
);
const source = await serialize(content, {
parseFrontmatter: false,
mdxOptions: {

View File

@@ -4,13 +4,6 @@ import glob from "fast-glob";
import pMap from "p-map";
import pMemoize from "p-memoize";
import matter from "gray-matter";
import removeMarkdown from "remove-markdown";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeSanitize from "rehype-sanitize";
import remarkSmartypants from "remark-smartypants";
import rehypeStringify from "rehype-stringify";
import { formatDate } from "./format-date";
import type { NoteFrontMatter } from "../../types";
@@ -39,28 +32,41 @@ export const getNoteData = async (
const rawContent = await fs.readFile(fullPath, "utf8");
const { data, content } = matter(rawContent);
// allow *very* limited markdown to be used in post titles
const htmlTitle = String(
await unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeSanitize, { tagNames: ["code", "em", "strong"] })
.use(remarkSmartypants, {
quotes: true,
dashes: "oldschool",
backticks: false,
ellipses: false,
})
.use(rehypeStringify, { allowDangerousHtml: true })
.process(data.title)
const { unified } = await import("unified");
const { remarkParse, remarkSmartypants, remarkRehype, rehypeSanitize, rehypeStringify } = await import(
"./remark-rehype-plugins"
);
// allow *very* limited markdown to be used in post titles
const parseTitle = async (title: string, allowedTags: string[] = []): Promise<string> => {
return String(
await unified()
.use(remarkParse)
.use(remarkSmartypants, {
quotes: true,
dashes: "oldschool",
backticks: false,
ellipses: false,
})
.use(remarkRehype)
.use(rehypeSanitize, { tagNames: allowedTags })
.use(rehypeStringify)
.process(title)
);
};
// process title as both plain and stylized
const [title, htmlTitle] = await Promise.all([
parseTitle(data.title),
parseTitle(data.title, ["code", "em", "strong"]),
]);
// return both the parsed YAML front matter (with a few amendments) and the raw, unparsed markdown content
return {
frontMatter: {
...(data as Partial<NoteFrontMatter>),
// zero markdown title:
title: removeMarkdown(data.title),
title,
htmlTitle,
slug,
permalink: `${process.env.BASE_URL}/notes/${slug}/`,

View File

@@ -1,12 +1,11 @@
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";
import { PrismaClient } from "@prisma/client";
// creating PrismaClient here prevents next.js from starting too many concurrent prisma instances and exhausting the
// number of connection pools available (especially when hot reloading from `next dev`).
// https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
const prismaClientSingleton = () => {
return new PrismaClient().$extends(withAccelerate());
return new PrismaClient();
};
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

View File

@@ -0,0 +1,9 @@
export { default as rehypePrism } from "rehype-prism-plus";
export { default as rehypeSanitize } from "rehype-sanitize";
export { default as rehypeSlug } from "rehype-slug";
export { default as rehypeStringify } from "rehype-stringify";
export { default as remarkGfm } from "remark-gfm";
export { default as remarkParse } from "remark-parse";
export { default as remarkRehype } from "remark-rehype";
export { default as remarkSmartypants } from "remark-smartypants";
export { default as remarkUnwrapImages } from "remark-unwrap-images";

View File

@@ -132,7 +132,6 @@ export const darkTheme = createTheme({
},
});
// @ts-ignore
export const globalStyles = globalCss(
// @ts-ignore
...normalizeCss({