Merge pull request 'Feat/wiki' (#38) from feat/wiki into main
Deploy Next.js via Docker / deploy (push) Successful in 5m26s

Reviewed-on: Schanbro/PsalmTafel#38
This commit was merged in pull request #38.
This commit is contained in:
robin committed 2026-08-06 15:42:35 +00:00
commit e08ef095e0
16 files changed
+310 -24

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ PsalmTafel is a real-time display system designed for choirs. It enables the cho
For detailed installation guides and deployment instructions, please visit our Wiki:
* [PsalmTafel Wiki – Installation Guide](https://git.schamagusa.de/Schanbro/PsalmTafel/wiki/Installation)
* [PsalmTafel Wiki – Installation Guide](https://psalmtafel.gem.schamagusa.de/wiki/installation)
---
+5 -1
View File
@@ -1,7 +1,9 @@
// @wikiCategory: Liederbücher
import { NextResponse } from "next/server";
import { getSongbooks, addSongbook } from "@/lib/db/managing";
// @wikiDescription: Liste aller Liederbücher abrufen
export async function GET() {
try {
const songbooks = await getSongbooks();
@@ -10,6 +12,8 @@ export async function GET() {
return NextResponse.json({ success: false, message: error}, { status: 500})
}
}
// @wikiDescription: Neues Liederbuch erstellen
export async function POST(request: Request) {
try {
const { name, language } = await request.json();
+3
View File
@@ -1,6 +1,9 @@
// @wikiCategory: Lieder
import { NextResponse } from "next/server";
import { getSongInfos } from "@/lib/db/managing";
// @wikiDescription: Informationen eines Liedes abrufen
export async function GET(
request: Request,
{ params }: { params: Promise<{ id: string }> }
+3
View File
@@ -1,6 +1,9 @@
// @wikiCategory: Lieder
import { NextResponse } from "next/server";
import { attachSongToSongbook } from "@/lib/db/managing";
// @wikiDescription: Lied zu einem Liederbuch hinzufügen
export async function POST(request: Request) {
try {
const body = await request.json();
+3
View File
@@ -1,6 +1,9 @@
// @wikiCategory: Lieder
import { NextResponse } from "next/server";
import { removeSongfromSongbook } from "@/lib/db/managing";
// @wikiDescription: Lied von einem Liederbuch entfernen
export async function POST(request: Request) {
try {
const body = await request.json();
+5
View File
@@ -1,7 +1,10 @@
// @wikiCategory: Lieder
import { NextResponse } from "next/server";
import { getSongs, addSongToSongbook } from "@/lib/db/managing";
// @wikiDescription: Liste aller Lieder abrufen
export async function GET() {
const songs = await getSongs();
if (songs) {
@@ -10,6 +13,8 @@ export async function GET() {
return NextResponse.json({ success: false}, { status: 500})
}
}
// @wikiDescription: Lied in einem Liederbuch erstellen
export async function POST(request: Request) {
try {
const { title, songbookId, number } = await request.json();
+4
View File
@@ -1,3 +1,5 @@
// @wikiCategory: Stream
import { NextResponse } from "next/server";
import { getSong } from "@/lib/db/managing";
@@ -8,10 +10,12 @@ let currentSong = {
title: ""
};
// @wikiDescription: Akutell gestreamtes Lied abrufen
export async function GET() {
return NextResponse.json(currentSong)
}
// @wikiDescription: Lied zum Streamen festlegen
export async function POST(request: Request) {
try {
const data = await request.json();
+22 -13
View File
@@ -4,7 +4,8 @@ import { MDXRemote } from 'next-mdx-remote/rsc';
import rehypePrettyCode from 'rehype-pretty-code';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import { Callout, Grid, Card, Steps, Step, InlineCode, CodeBlockContainer } from '@/components/mdx-components';
import { Callout, Grid, Card, Steps, Step, InlineCode, CodeBlockContainer, API } from '@/components/mdx-components';
import Article from '@/components/wiki/Article';
const mdxOptions = {
mdxOptions: {
@@ -43,6 +44,7 @@ const mdxComponents = {
Card,
Steps,
Step,
API,
// Custom Typography Überschreibungen
code: InlineCode,
pre: CodeBlockContainer,
@@ -66,19 +68,26 @@ export default async function Page({ params }: PageProps) {
}
return (
<article className="prose prose-invert prose-blue max-w-4xl mx-auto p-6 md:p-12 min-h-screen">
<header className="mb-8 border-b border-zinc-800 pb-6">
<h1 className="text-4xl font-extrabold text-white mb-2 m-0">{article.title}</h1>
{article.updatedAt && (
<p className="text-zinc-500 text-sm m-0">Zuletzt aktualisiert: {article.updatedAt}</p>
)}
</header>
// <article className="prose prose-invert prose-blue max-w-4xl mx-auto p-6 md:p-12 min-h-screen">
// <header className="mb-8 border-b border-zinc-800 pb-6">
// <h1 className="text-4xl font-extrabold text-white mb-2 m-0">{article.title}</h1>
// {article.updatedAt && (
// <p className="text-zinc-500 text-sm m-0">Zuletzt aktualisiert: {article.updatedAt}</p>
// )}
// </header>
// <MDXRemote
// source={article.rawContent}
// components={mdxComponents}
// options={mdxOptions as any}
// />
// </article>
<Article title={article.title} updatedAt={article.updatedAt}>
<MDXRemote
source={article.rawContent}
components={mdxComponents}
options={mdxOptions as any}
/>
</article>
source={article.rawContent}
components={mdxComponents}
options={mdxOptions as any}
/>
</Article>
);
}
+34
View File
@@ -0,0 +1,34 @@
import { getAllApis } from "@/lib/wiki";
import Article from '@/components/wiki/Article';
import { API } from '@/components/mdx-components';
export default async function Page() {
const allApis = await getAllApis();
// Gruppiert die APIs nach ihrer Kategorie
const groupedApis = Object.groupBy(allApis, (api) => api.category);
return (
<Article title="API-Endpunkte">
{Object.entries(groupedApis).map(([category, apis]) => (
<div key={category} className="mb-10">
{/* Kategorie-Überschrift wird nur EINMAL pro Kategorie gerendert */}
<h2 className="text-2xl font-bold text-white mt-10 mb-4 border-b border-zinc-800 pb-2">
{category}
</h2>
{/* Routen innerhalb dieser Kategorie durchgehen */}
{apis?.map((api, index) => (
<div key={index} className="my-4">
{api.methods.map((method, mIndex) => (
<API route={api.route} method={method.method} key={mIndex}>
{method.description}
</API>
))}
</div>
))}
</div>
))}
</Article>
);
}
+42
View File
@@ -117,3 +117,45 @@ export function CodeBlockContainer({ children, ...props }: React.HTMLAttributes<
</div>
);
}
export function API({
method = 'GET',
route,
children
}: {
method?: string;
route: string;
children?: React.ReactNode;
}) {
const methodUpper = method.toUpperCase();
// Farben für die verschiedenen HTTP-Methoden
const methodStyles: Record<string, string> = {
GET: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/30',
POST: 'bg-blue-500/10 text-blue-400 border-blue-500/30',
PUT: 'bg-amber-500/10 text-amber-400 border-amber-500/30',
PATCH: 'bg-orange-500/10 text-orange-400 border-orange-500/30',
DELETE: 'bg-rose-500/10 text-rose-400 border-rose-500/30',
};
const badgeStyle = methodStyles[methodUpper] || 'bg-zinc-800 text-zinc-300 border-zinc-700';
return (
<div className="my-6 rounded-xl border border-zinc-800 bg-zinc-900/50 overflow-hidden">
{/* Route & Methoden-Header */}
<div className="flex items-center gap-3 p-4 bg-zinc-900 border-b border-zinc-800 font-mono text-sm">
<span className={`px-2.5 py-1 rounded-md text-xs font-bold border ${badgeStyle}`}>
{methodUpper}
</span>
<span className="text-zinc-200 font-semibold">/api/{route}</span>
</div>
{/* Beschreibung / Inhalt */}
{children && (
<div className="p-4 text-sm text-zinc-400 leading-relaxed [&>p]:m-0">
{children}
</div>
)}
</div>
);
}
+22
View File
@@ -0,0 +1,22 @@
import { ReactNode } from "react";
interface ArticleProps {
title: string;
updatedAt?: string;
children: ReactNode
}
export default function Article({ title, updatedAt, children }: ArticleProps) {
return (
<article className="prose prose-invert prose-blue max-w-4xl mx-auto p-6 md:p-12 min-h-screen">
<header className="mb-8 border-b border-zinc-800 pb-6">
<h1 className="text-4xl font-extrabold text-white mb-2 m-0">{title}</h1>
{updatedAt && (
<p className="text-zinc-500 text-sm m-0">Zuletzt aktualisiert: {updatedAt}</p>
)}
</header>
{children}
</article>
);
}
-6
View File
@@ -1,6 +0,0 @@
---
title: API
updatedAt: "2026-08-05"
---
comming soon...
+154 -1
View File
@@ -1,6 +1,8 @@
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import ts from 'typescript';
import { ApiRoute, ApiMethod } from '@/types/api';
export type WikiArticle = {
slug: string;
@@ -16,7 +18,6 @@ export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | nul
const fullPath = path.join(wikiDirectory, `${slug}.mdx`);
const fileContents = fs.readFileSync(fullPath, "utf-8");
// Metadaten und Inhalt parsen
const { data, content } = matter(fileContents);
return {
@@ -30,3 +31,155 @@ export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | nul
return null;
}
}
export function getAllTsFiles(dirPath: string): string[] {
let results: string[] = [];
if (!fs.existsSync(dirPath)) return results;
const list = fs.readdirSync(dirPath);
list.forEach((file) => {
const filePath = path.join(dirPath, file);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
results = results.concat(getAllTsFiles(filePath));
} else if (filePath.endsWith('.ts') && !filePath.endsWith('.d.ts')) {
results.push(filePath);
}
});
return results;
}
/**
* Liest die Kategorie aus der Datei aus (@wikiCategory) oder ermittelt sie aus dem Ordnernamen.
*/
export function filterCategory(
content: string,
filePath: string,
prefix: string = '@wikiCategory'
): string {
// 1. In Kommentaren nach @wikiCategory suchen
const lines = content.split('\n');
for (const line of lines) {
const cleaned = line.replace(/^\/\/\s*/, '').replace(/^\/\*\*?\s*/, '').replace(/\*\/$/, '').trim();
if (cleaned.startsWith(prefix)) {
let category = cleaned.slice(prefix.length).trim().replace(/^:\s*/, '');
if (category) return category;
}
}
// 2. Fallback: Ersten Ordnernamen unter app/api/ als Kategorie nutzen
const normalizedPath = filePath.replace(/\\/g, '/');
const apiMatch = normalizedPath.match(/app\/api\/([^/]+)/);
if (apiMatch && apiMatch[1]) {
const folderName = apiMatch[1];
// Ersten Buchstaben großschreiben (z. B. "stream" -> "Stream")
return folderName.charAt(0).toUpperCase() + folderName.slice(1);
}
return 'Allgemein';
}
/**
* Parst TypeScript-Code via AST und extrahiert HTTP-Methoden sowie deren Kommentare.
*/
export function filterMethods(
content: string,
prefix: string = '@wikiDescription'
): ApiMethod[] {
const sourceFile = ts.createSourceFile(
'temp.ts',
content,
ts.ScriptTarget.Latest,
/* setParentNodes */ true
);
const methods: ApiMethod[] = [];
const validMethods = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
ts.forEachChild(sourceFile, (node) => {
if (ts.isFunctionDeclaration(node) && node.name) {
const functionName = node.name.text;
if (validMethods.has(functionName)) {
let description = '';
const commentRanges = ts.getLeadingCommentRanges(content, node.pos);
if (commentRanges && commentRanges.length > 0) {
const lastCommentRange = commentRanges[commentRanges.length - 1];
const rawComment = content.substring(
lastCommentRange.pos,
lastCommentRange.end
);
const cleanedComment = rawComment
.replace(/^\/\/\s*/, '')
.replace(/^\/\*\*?\s*/, '')
.replace(/\*\/$/, '')
.split('\n')
.map((line) => line.replace(/^\s*\*\s?/, '').trim())
.join(' ')
.trim();
if (cleanedComment.startsWith(prefix)) {
let textAfterPrefix = cleanedComment.slice(prefix.length).trim();
textAfterPrefix = textAfterPrefix.replace(/^:\s*/, '');
description = textAfterPrefix;
}
}
methods.push({
method: functionName,
description: description || 'Keine Beschreibung vorhanden.',
});
}
}
});
return methods;
}
/**
* Liest alle API-Dateien dynamisch aus und wandelt sie in ApiRoute-Objekte um.
*/
export async function getAllApis(): Promise<ApiRoute[]> {
try {
const apiBasePath = path.join(process.cwd(), "app/api");
const allTsFiles = getAllTsFiles(apiBasePath);
const routes: ApiRoute[] = [];
allTsFiles.forEach((filePath) => {
const fileContents = fs.readFileSync(filePath, "utf-8");
// 1. Methoden extrahieren
const methods = filterMethods(fileContents, "@wikiDescription");
// Nur Routen hinzufügen, die auch API-Methoden exportieren
if (methods.length > 0) {
// 2. Kategorie ermitteln
const category = filterCategory(fileContents, filePath, "@wikiCategory");
// 3. Route-Pfad automatisch aus dem Dateipfad generieren (app/api/stream/currentID/route.ts -> stream/currentID)
const relativePath = path.relative(apiBasePath, filePath).replace(/\\/g, '/');
const routePath = relativePath
.replace(/\/route\.ts$/, '')
.replace(/\.ts$/, '');
routes.push({
route: routePath,
category,
methods,
});
}
});
return routes;
} catch (error) {
console.error("Fehler beim Auslesen der API-Dateien:", error);
return [];
}
}
+1 -1
View File
@@ -38,7 +38,7 @@
"eslint": "^9",
"eslint-config-next": "16.2.9",
"tailwindcss": "^4",
"typescript": "^5"
"typescript": "^5.9.3"
},
"pnpm": {
"onlyBuiltDependencies": [
+1 -1
View File
@@ -91,7 +91,7 @@ importers:
specifier: ^4
version: 4.3.1
typescript:
specifier: ^5
specifier: ^5.9.3
version: 5.9.3
packages:
+10
View File
@@ -0,0 +1,10 @@
export interface ApiMethod {
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | string;
description: string;
}
export interface ApiRoute {
category: string;
route: string;
methods: ApiMethod[];
}