From aee4b8c5670809c7b5b152619e3f29ea855d42b8 Mon Sep 17 00:00:00 2001 From: Robin Schanbacher Date: Tue, 4 Aug 2026 16:02:02 +0200 Subject: [PATCH] style: adjust style --- app/globals.css | 34 ++++++++++++++++ app/wiki/[slug]/page.tsx | 26 ++++++++---- components/mdx-components.tsx | 76 ++++++++++++++++++----------------- data/wiki/pages/test.mdx | 8 ++-- lib/wiki.ts | 44 +++++++------------- 5 files changed, 110 insertions(+), 78 deletions(-) diff --git a/app/globals.css b/app/globals.css index 61afa29..1494310 100644 --- a/app/globals.css +++ b/app/globals.css @@ -58,4 +58,38 @@ pre code { background-color: transparent !important; padding: 0 !important; border: none !important; +} + +/* Shiki / Rehype Pretty Code Block Container */ +figure[data-rehype-pretty-code-figure] { + margin-top: 1.5rem; + margin-bottom: 1.5rem; + border-radius: 0.75rem; + overflow: hidden; + border: 1px solid #27272a; /* Tailwind zinc-800 */ + background-color: #0d1117; /* Dunkler VS-Code Hintergrund */ +} + +/* Der Titel/Dateiname (falls im MDX angegeben) */ +div[data-rehype-pretty-code-title] { + background-color: #161b22; + border-bottom: 1px solid #27272a; + padding: 0.5rem 1rem; + font-family: monospace; + font-size: 0.75rem; + color: #8b949e; +} + +/* Der eigentliche Code-Bereich */ +figure[data-rehype-pretty-code-figure] pre { + margin: 0 !important; + padding: 1rem !important; + background-color: transparent !important; + overflow-x: auto; + font-size: 0.875rem; + line-height: 1.7; +} + +figure[data-rehype-pretty-code-figure] code { + font-family: var(--font-mono, monospace); } \ No newline at end of file diff --git a/app/wiki/[slug]/page.tsx b/app/wiki/[slug]/page.tsx index cb74661..6bad611 100644 --- a/app/wiki/[slug]/page.tsx +++ b/app/wiki/[slug]/page.tsx @@ -1,9 +1,8 @@ import { getWikiPageBySlug } from '@/lib/wiki'; import { notFound } from 'next/navigation'; -import rehypePrettyCode from 'rehype-pretty-code'; - import { MDXRemote } from 'next-mdx-remote/rsc'; -import { Callout, Grid, Card, Steps, Step, InlineCode, PreBlock } from '@/components/mdx-components'; +import rehypePrettyCode from 'rehype-pretty-code'; +import { Callout, Grid, Card, Steps, Step, InlineCode } from '@/components/mdx-components'; const mdxOptions = { mdxOptions: { @@ -11,7 +10,7 @@ const mdxOptions = { [ rehypePrettyCode, { - theme: 'github-dark', // oder 'one-dark-pro', 'nord', etc. + theme: 'github-dark', keepBackground: true, }, ], @@ -20,12 +19,18 @@ const mdxOptions = { }; const mdxComponents = { + // Eigene UI-Komponenten Callout, Grid, Card, Steps, Step, - h2: (props: any) =>

, + + // Custom Typography Überschreibungen + code: InlineCode, + h1: (props: any) =>

, + h2: (props: any) =>

, + h3: (props: any) =>

, }; type PageProps = { @@ -43,9 +48,14 @@ export default async function Page({ params }: PageProps) { } return ( -
-

{article.title}

- {/* Direkte MDX-Rendering-Komponente von Next.js */} +
+
+

{article.title}

+ {article.updatedAt && ( +

Zuletzt aktualisiert: {article.updatedAt}

+ )} +
+ -
-
- {type === 'info' && } - {type === 'warning' && } +
+
+ {type === 'info' && } + {type === 'warning' && } + {type === 'error' && } + {type === 'success' && }
-
{children}
+
{children}
); } -// 2. Card Grid (Für Übersichtsseiten) +// 2. Grid & Cards export function Grid({ children }: { children: React.ReactNode }) { return
{children}
; } -export function Card({ title, href, children }: { title: string, href: string, children: React.ReactNode }) { +export function Card({ title, href, children }: { title: string; href: string; children: React.ReactNode }) { return ( - +

{title}

-
+
{children}
); } -// 3. Steps (Für nummerierte Anleitungen) +// 3. Steps export function Steps({ children }: { children: React.ReactNode }) { return (
@@ -47,39 +55,33 @@ export function Steps({ children }: { children: React.ReactNode }) { ); } -export function Step({ title, children }: { title: string, children: React.ReactNode }) { +export function Step({ title, children }: { title: string; children: React.ReactNode }) { return (
-
- {/* Die Nummerierung macht CSS automatisch, siehe unten */} -
-

{title}

-
{children}
+
+

{title}

+
{children}
); } -export function InlineCode({ children }: { children?: React.ReactNode }) { +// Custom Inline Code (verhindert das Erben auf große Codeblöcke) +export function InlineCode({ children, className, ...props }: React.HTMLAttributes) { + // Wenn 'data-theme' oder 'data-language' existiert, kommt das Element aus rehype-pretty-code (Code-Block) + const isCodeBlock = props && ('data-theme' in props || 'data-language' in props); + + // Falls es Teil eines großen Codeblocks ist -> normales ohne Inline-Styling rendern + if (isCodeBlock || className?.includes('language-')) { + return {children}; + } + + // Ansonsten: Unser schickes Inline-Code-Design anwenden return ( - + {children} ); -} - -// 2. Code Block (für mehrzeiligen Code) -export function PreBlock({ children }: { children?: React.ReactNode }) { - return ( -
- {/* Optionaler Dekorations-Header für den Codeblock */} -
-
-
-
-
-
-        {children}
-      
-
- ); } \ No newline at end of file diff --git a/data/wiki/pages/test.mdx b/data/wiki/pages/test.mdx index c20ee36..b669802 100644 --- a/data/wiki/pages/test.mdx +++ b/data/wiki/pages/test.mdx @@ -1,8 +1,9 @@ --- title: Projekt Starten +updatedAt: "2026-08-04" --- -# Willkommen im Wiki +Willkommen im offiziellen Wiki! Hier findest du alle Informationen zum Projekt. @@ -22,7 +23,7 @@ title: Projekt Starten Führe den Installer aus: - `npm install` + `pnpm install` @@ -37,5 +38,4 @@ title: Projekt Starten ```typescript function sayHello(name: string): string { return `Hallo, ${name}!`; -} -``` \ No newline at end of file +} \ No newline at end of file diff --git a/lib/wiki.ts b/lib/wiki.ts index 08dbdd4..c674267 100644 --- a/lib/wiki.ts +++ b/lib/wiki.ts @@ -1,14 +1,6 @@ import fs from 'fs'; import path from 'path'; import matter from 'gray-matter'; -import { remark } from 'remark'; -import html from 'remark-html'; -import rehypePrettyCode from 'rehype-pretty-code'; - -const options = { - theme: 'github-dark', // oder 'nord', 'one-dark-pro', etc. - keepBackground: true, -}; export type WikiArticle = { slug: string; @@ -20,27 +12,21 @@ export type WikiArticle = { const wikiDirectory = path.join(process.cwd(), "data/wiki/pages"); export async function getWikiPageBySlug(slug: string): Promise { - try { - const fullPath = path.join(wikiDirectory, `${slug}.mdx`); - const fileContents = fs.readFileSync(fullPath, "utf-8"); + try { + const fullPath = path.join(wikiDirectory, `${slug}.mdx`); + const fileContents = fs.readFileSync(fullPath, "utf-8"); - // read metadata - const { data, content } = matter(fileContents); + // Metadaten und Inhalt parsen + const { data, content } = matter(fileContents); - // convert markdown in HTML - const processedContent = await remark() - .use(html) - .process(content); - const contentHtml = processedContent.toString(); - - return { - slug, - rawContent: content, - title: data.title || 'Unbenannt', - updatedAt: data.updatedAt || null, - ...data, - } as WikiArticle; - } catch (error) { - return null; - } + return { + slug, + rawContent: content, + title: data.title || 'Unbenannt', + updatedAt: data.updatedAt || null, + ...data, + } as WikiArticle; + } catch (error) { + return null; + } } \ No newline at end of file