Compare commits

..

No commits in common. "15b7b30b088688b726379e4c49ff62e0f5b0ff7b" and "cbcf6a731bf30a89508c99c2c776cef06d5695ed" have entirely different histories.

8 changed files with 8 additions and 1444 deletions

1
.env
View File

@ -1 +0,0 @@
DUMMY_HTML_DIR=./development-test-data-dir/

3
.gitignore vendored
View File

@ -27,8 +27,7 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
# local env files # local env files
.env.local .env.development
.env.development.local
# vercel # vercel
.vercel .vercel

View File

@ -1,37 +0,0 @@
import { unified } from 'unified';
import remarkGfm from "remark-gfm";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeSanitize from "rehype-sanitize";
import rehypeHighlight from "rehype-highlight";
import rehypeReact from "rehype-react";
import * as prod from 'react/jsx-runtime';
import { readFile } from 'node:fs/promises';
async function markPostString() {
let path = ""
if ('DUMMY_HTML_DIR' in process.env && typeof process.env.DUMMY_HTML_DIR === "string") {
path = process.env.DUMMY_HTML_DIR + "test1.md";
}
return await readFile(path, "utf-8")
}
export default async function Mark() {
let content = await markPostString();
let result = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeSanitize)
.use(rehypeHighlight)
.use(rehypeReact, {
Fragment: prod.Fragment,
jsx: prod.jsx,
jsxs: prod.jsxs,
})
.processSync(content)
return result.result;
}

View File

@ -25,14 +25,16 @@ const options: HTMLReactParserOptions = {
export default async function Post({ params }: { params: { slug: string } }) { export default async function Post({ params }: { params: { slug: string } }) {
let content; let content;
const dummySlug = DummyPostSlug(); const dummySlug = await DummyPostSlug();
if (dummySlug === params.slug) { if (dummySlug === params.slug) {
content = await DummyPostString(); content = await DummyPostString();
// console.log(content);
} else { } else {
content = await getPost(params.slug); content = await getPost(params.slug);
} }
content = DOMPurify(new JSDOM("<!DOCTYPE html>").window).sanitize(content); content = DOMPurify(new JSDOM("<!DOCTYPE html>").window).sanitize(content);
// console.log(content)
const elem = parse(content, options); const elem = parse(content, options);
return ( return (

View File

@ -1,21 +1,13 @@
import { readFile } from 'node:fs/promises'; import { promises as fsp } from 'fs'
export async function MarkPostString() {
let path = ""
if ('DUMMY_HTML_DIR' in process.env && typeof process.env.DUMMY_HTML_DIR === "string") {
path = process.env.DUMMY_HTML_DIR + "test1.md";
}
return await readFile(path, "utf-8")
}
export async function DummyPostString() { export async function DummyPostString() {
let path = "" let path = ""
if ('DUMMY_HTML_DIR' in process.env && typeof process.env.DUMMY_HTML_DIR === "string") { if ('DUMMY_HTML_DIR' in process.env && typeof process.env.DUMMY_HTML_DIR === "string") {
path = process.env.DUMMY_HTML_DIR + "test1.html"; path = process.env.DUMMY_HTML_DIR + "test1.html";
} }
return await readFile(path, "utf-8") return await fsp.readFile(path, "utf-8")
} }
export function DummyPostSlug() { export async function DummyPostSlug() {
return "dummy-post" return "dummy-post"
} }

View File

@ -1,15 +0,0 @@
# Post Title
## Introduction
Hi there! Do you see me?
```go
import "fmt"
func main() {
fmt.Println("hello world")
}
```
That's the `hello world` code!

View File

@ -26,19 +26,10 @@
"postcss": "8.4.30", "postcss": "8.4.30",
"react": "18.3.1", "react": "18.3.1",
"react-dom": "18.3.1", "react-dom": "18.3.1",
"react-remark": "^2.1.0",
"redis": "^4.6.13", "redis": "^4.6.13",
"rehype-highlight": "^7.0.0",
"rehype-react": "^8.0.0",
"rehype-sanitize": "^6.0.0",
"rehype-stringify": "^10.0.0",
"remark-gfm": "^4.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.0",
"sharp": "^0.33.3", "sharp": "^0.33.3",
"tailwindcss": "3.3.3", "tailwindcss": "3.3.3",
"typescript": "5.2.2", "typescript": "5.2.2"
"unified": "^11.0.4"
}, },
"devDependencies": { "devDependencies": {
"prettier": "3.0.3" "prettier": "3.0.3"

1367
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff