From 64564a6fee02708d375a349d75ce49d515e66f8d Mon Sep 17 00:00:00 2001 From: schererleander Date: Wed, 25 Jun 2025 01:00:49 +0200 Subject: add markdown-based blog --- src/pages/Post.tsx | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/pages/Post.tsx (limited to 'src/pages/Post.tsx') diff --git a/src/pages/Post.tsx b/src/pages/Post.tsx new file mode 100644 index 0000000..17022d2 --- /dev/null +++ b/src/pages/Post.tsx @@ -0,0 +1,75 @@ +import { useEffect, useState } from "react"; +import { useParams, Link } from "react-router-dom"; +import matter from "gray-matter"; +import ReactMarkdown from "react-markdown"; +import CodeSnippet from "../components/CodeSnippet"; +import LinkWithIcon from "../components/LinkWithIcon"; +import NotFoundPage from "./404Page"; + +interface PostMeta { + title: string; + date: string; + cover?: string; +} + +export default function Post() { + const { slug } = useParams<{ slug: string }>(); + const [meta, setMeta] = useState(null); + const [content, setContent] = useState(""); + const [notFound, setNotFound] = useState(false); + + useEffect(() => { + import(`../blog/${slug}.md?raw`) + .then((m) => { + const { data, content } = matter(m.default); + setMeta(data as PostMeta); + setContent(content); + }) + .catch(() => setNotFound(true)); + }, [slug]); + + if (!meta) return null; + if (notFound) return ; + + return ( +
+ + ← Zurück zum Blog + + + {meta.cover && ( + {meta.title} + )} + +

{meta.title}

+

+ {new Date(meta.date).toLocaleDateString("de-DE")} +

+ +
+ ; + }, + + a({ href = "", children, ...props }) { + return ( + + {children} + + ); + }, + }} + > + {content} + +
+
+ ); +} \ No newline at end of file -- cgit v1.3.1