From 49ed2577accbc73d01162a049e886e0fbd517cbc Mon Sep 17 00:00:00 2001 From: Robin Schanbacher Date: Tue, 4 Aug 2026 15:20:31 +0200 Subject: [PATCH] feat: add own wiki --- app/wiki/[slug]/page.tsx | 31 +++++++++++++++++++++++++ data/wiki/pages/installation.md | 5 +++++ lib/wiki.ts | 40 +++++++++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 29 ++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 app/wiki/[slug]/page.tsx create mode 100644 lib/wiki.ts diff --git a/app/wiki/[slug]/page.tsx b/app/wiki/[slug]/page.tsx new file mode 100644 index 0000000..4b4c44f --- /dev/null +++ b/app/wiki/[slug]/page.tsx @@ -0,0 +1,31 @@ +import { getWikiPageBySlug } from '@/lib/wiki'; +import { notFound } from 'next/navigation'; + +type PageProps = { + params: Promise<{ + slug: string; + }>; +}; + +export default async function Page({ params }: PageProps) { const { slug } = await params; + const article = await getWikiPageBySlug(slug); + + if (!article) { + notFound(); // Zeigt die 404-Seite, wenn z. B. installation.md nicht existiert + } + + return ( +
+

{article.title}

+ {article.updatedAt && ( +

Stand: {article.updatedAt}

+ )} + + {/* Gerendertes Markdown-HTML anzeigen */} +
+
+ ); +} \ No newline at end of file diff --git a/data/wiki/pages/installation.md b/data/wiki/pages/installation.md index df0aa00..a6f232f 100644 --- a/data/wiki/pages/installation.md +++ b/data/wiki/pages/installation.md @@ -1,3 +1,8 @@ +--- +title: Installation & Setup +updatedAt: "2026-08-04" +---- + # Installation ## Test diff --git a/lib/wiki.ts b/lib/wiki.ts new file mode 100644 index 0000000..714f935 --- /dev/null +++ b/lib/wiki.ts @@ -0,0 +1,40 @@ +import fs from 'fs'; +import path from 'path'; +import matter from 'gray-matter'; +import { remark } from 'remark'; +import html from 'remark-html'; + +export type WikiArticle = { + slug: string; + title: string; + contentHtml: string; + updatedAt?: string; +}; + +const wikiDirectory = path.join(process.cwd(), "data/wiki/pages"); + +export async function getWikiPageBySlug(slug: string): Promise { + try { + const fullPath = path.join(wikiDirectory, `${slug}.md`); + const fileContents = fs.readFileSync(fullPath, "utf-8"); + + // read metadata + const { data, content } = matter(fileContents); + + // convert markdown in HTML + const processedContent = await remark() + .use(html) + .process(content); + const contentHtml = processedContent.toString(); + + return { + slug, + contentHtml, + title: data.title || 'Unbenannt', + updatedAt: data.updatedAt || null, + ...data, + } as WikiArticle; + } catch (error) { + return null; + } +} \ No newline at end of file diff --git a/package.json b/package.json index fde8c21..44162da 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "devDependencies": { "@tailwindcss/postcss": "^4", + "@tailwindcss/typography": "^0.5.20", "@types/better-sqlite3": "^7.6.13", "@types/node": "^20", "@types/react": "^19", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6e183a3..94c545b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,6 +39,9 @@ importers: '@tailwindcss/postcss': specifier: ^4 version: 4.3.1 + '@tailwindcss/typography': + specifier: ^0.5.20 + version: 0.5.20(tailwindcss@4.3.1) '@types/better-sqlite3': specifier: ^7.6.13 version: 7.6.13 @@ -554,6 +557,11 @@ packages: '@tailwindcss/postcss@4.3.1': resolution: {integrity: sha512-dNJuNbdEJT/SWRuXTYP1WSamelsz3ztkUsdtWQPjrexysrTpaEPM40P/71knXiXLYEojqPOEGitVLLpPMS5T6A==} + '@tailwindcss/typography@0.5.20': + resolution: {integrity: sha512-hwbzQuNUfcPvbegQFatVPl/MY/tcM9KLl963hQ5laJKPh81TEZ1+dNG9PirGvcaDBkp+BCshExAyKVPW91dozw==} + peerDependencies: + tailwindcss: '>=3.0.0 || >=4.0.0 || insiders' + '@tybys/wasm-util@0.10.3': resolution: {integrity: sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==} @@ -966,6 +974,11 @@ packages: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} + cssesc@3.0.0: + resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} + engines: {node: '>=4'} + hasBin: true + csstype@3.2.3: resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==} @@ -1952,6 +1965,10 @@ packages: resolution: {integrity: sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==} engines: {node: '>= 0.4'} + postcss-selector-parser@6.0.10: + resolution: {integrity: sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w==} + engines: {node: '>=4'} + postcss@8.4.31: resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==} engines: {node: ^10 || ^12 || >=14} @@ -2802,6 +2819,11 @@ snapshots: postcss: 8.5.15 tailwindcss: 4.3.1 + '@tailwindcss/typography@0.5.20(tailwindcss@4.3.1)': + dependencies: + postcss-selector-parser: 6.0.10 + tailwindcss: 4.3.1 + '@tybys/wasm-util@0.10.3': dependencies: tslib: 2.8.1 @@ -3223,6 +3245,8 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 + cssesc@3.0.0: {} + csstype@3.2.3: {} damerau-levenshtein@1.0.8: {} @@ -4441,6 +4465,11 @@ snapshots: possible-typed-array-names@1.1.0: {} + postcss-selector-parser@6.0.10: + dependencies: + cssesc: 3.0.0 + util-deprecate: 1.0.2 + postcss@8.4.31: dependencies: nanoid: 3.3.15