Files
psalmtafel-webservice/lib/wiki.ts
T
2026-08-04 16:02:02 +02:00

32 lines
775 B
TypeScript

import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
export type WikiArticle = {
slug: string;
title: string;
rawContent: string;
updatedAt?: string;
};
const wikiDirectory = path.join(process.cwd(), "data/wiki/pages");
export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | null> {
try {
const fullPath = path.join(wikiDirectory, `${slug}.mdx`);
const fileContents = fs.readFileSync(fullPath, "utf-8");
// Metadaten und Inhalt parsen
const { data, content } = matter(fileContents);
return {
slug,
rawContent: content,
title: data.title || 'Unbenannt',
updatedAt: data.updatedAt || null,
...data,
} as WikiArticle;
} catch (error) {
return null;
}
}