From 0ca7a97d26276345d3b66778545eb20027d68940 Mon Sep 17 00:00:00 2001 From: Suyono Date: Thu, 9 May 2024 22:31:01 +1000 Subject: [PATCH] wip: testing remark; trying to downgrade some libs --- app/mark/page.tsx | 21 +++++++++++++++++++++ app/post/[slug]/page.tsx | 4 +--- components/dummyPost.tsx | 14 +++++++++++--- dummies/test1.md | 15 +++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 app/mark/page.tsx create mode 100644 dummies/test1.md diff --git a/app/mark/page.tsx b/app/mark/page.tsx new file mode 100644 index 0000000..24cff28 --- /dev/null +++ b/app/mark/page.tsx @@ -0,0 +1,21 @@ +import { MarkPostString } from '@/components/dummyPost'; +import remarkGfm from "remark-gfm"; +import rehypeSanitize from "rehype-sanitize"; +import rehypeHighlight from "rehype-highlight"; +import remarkRehype from "remark-rehype"; +import remarkParse from "remark-parse"; +import { unified } from 'unified'; +import rehypeReact from "rehype-react"; +import * as prod from 'react/jsx-runtime'; + +export default async function Mark() { + let content = await MarkPostString(); + let result = unified() + .use(remarkParse) + .use(remarkGfm) + .use(remarkRehype) + .use(rehypeSanitize) + .use(rehypeHighlight) + .processSync(content) + +} \ No newline at end of file diff --git a/app/post/[slug]/page.tsx b/app/post/[slug]/page.tsx index f8f806d..47192e4 100644 --- a/app/post/[slug]/page.tsx +++ b/app/post/[slug]/page.tsx @@ -25,16 +25,14 @@ const options: HTMLReactParserOptions = { export default async function Post({ params }: { params: { slug: string } }) { let content; - const dummySlug = await DummyPostSlug(); + const dummySlug = DummyPostSlug(); if (dummySlug === params.slug) { content = await DummyPostString(); - // console.log(content); } else { content = await getPost(params.slug); } content = DOMPurify(new JSDOM("").window).sanitize(content); - // console.log(content) const elem = parse(content, options); return ( diff --git a/components/dummyPost.tsx b/components/dummyPost.tsx index 0804b8e..d3b5236 100644 --- a/components/dummyPost.tsx +++ b/components/dummyPost.tsx @@ -1,13 +1,21 @@ -import { promises as fsp } from 'fs' +import { readFile } from 'node:fs/promises'; + +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() { let path = "" if ('DUMMY_HTML_DIR' in process.env && typeof process.env.DUMMY_HTML_DIR === "string") { path = process.env.DUMMY_HTML_DIR + "test1.html"; } - return await fsp.readFile(path, "utf-8") + return await readFile(path, "utf-8") } -export async function DummyPostSlug() { +export function DummyPostSlug() { return "dummy-post" } \ No newline at end of file diff --git a/dummies/test1.md b/dummies/test1.md new file mode 100644 index 0000000..69bbccf --- /dev/null +++ b/dummies/test1.md @@ -0,0 +1,15 @@ +# Post Title + +## Introduction + +Hi there! Do you see me? + +```go +import "fmt" + +func main() { + fmt.Println("hello world") +} +``` + +That's the `hello world` code! \ No newline at end of file