This commit is contained in:
ZockerKatze
2025-06-16 17:47:03 +02:00
parent a93a259ee5
commit 1922125adb
7 changed files with 625 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
const postsDirectory = path.join(process.cwd(), 'posts');
export async function POST(request: Request) {
try {
const body = await request.json();
const { title, date, tags, summary, content } = body;
// Create slug from title
const slug = title
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/(^-|-$)/g, '');
// Create frontmatter
const frontmatter = matter.stringify(content, {
title,
date,
tags,
summary,
});
// Write the file
const filePath = path.join(postsDirectory, `${slug}.md`);
fs.writeFileSync(filePath, frontmatter);
return NextResponse.json({ success: true, slug });
} catch (error) {
console.error('Error creating post:', error);
return NextResponse.json(
{ error: 'Error creating post' },
{ status: 500 }
);
}
}