feat: add posts
This commit is contained in:
21
app/utils/db.server.ts
Normal file
21
app/utils/db.server.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
export let db: PrismaClient;
|
||||
|
||||
declare global {
|
||||
var __db: PrismaClient | undefined;
|
||||
}
|
||||
|
||||
// this is needed because in development we don't want to restart
|
||||
// the server with every change, but we want to make sure we don't
|
||||
// create a new connection to the DB with every change either.
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
db = new PrismaClient();
|
||||
db.$connect();
|
||||
} else {
|
||||
if (!global.__db) {
|
||||
global.__db = new PrismaClient();
|
||||
global.__db.$connect();
|
||||
}
|
||||
db = global.__db;
|
||||
}
|
26
app/utils/posts.server.ts
Normal file
26
app/utils/posts.server.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { remarkCodeHike } from "@code-hike/mdx";
|
||||
import { readFile } from "fs/promises";
|
||||
import { bundleMDX } from "mdx-bundler";
|
||||
import codeHikeTheme from "shiki/themes/one-dark-pro.json";
|
||||
|
||||
export const getMdxFile = async (path: string) => {
|
||||
const source = await readFile(path);
|
||||
return bundleMDX({
|
||||
source: source.toString(),
|
||||
mdxOptions() {
|
||||
return {
|
||||
remarkPlugins: [
|
||||
[
|
||||
remarkCodeHike,
|
||||
{
|
||||
theme: codeHikeTheme,
|
||||
lineNumbers: true,
|
||||
showCopyButton: true,
|
||||
autoImport: true,
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user