+
+
{post.title}
+
+ {post.pinned && (
+ 📌
+ )}
+
{post.date}
{post.summary}
diff --git a/src/app/api/admin/posts/raw/route.ts b/src/app/api/admin/posts/raw/route.ts
new file mode 100644
index 0000000..0b0ea93
--- /dev/null
+++ b/src/app/api/admin/posts/raw/route.ts
@@ -0,0 +1,22 @@
+import { NextRequest, NextResponse } from 'next/server';
+import fs from 'fs';
+import path from 'path';
+
+const postsDirectory = path.join(process.cwd(), 'posts');
+
+export async function GET(request: NextRequest) {
+ const { searchParams } = new URL(request.url);
+ const slug = searchParams.get('slug');
+ const folderPath = searchParams.get('path') || '';
+ if (!slug) {
+ return NextResponse.json({ error: 'Missing slug' }, { status: 400 });
+ }
+ const filePath = folderPath && folderPath.trim() !== ''
+ ? path.join(postsDirectory, folderPath, `${slug}.md`)
+ : path.join(postsDirectory, `${slug}.md`);
+ if (!fs.existsSync(filePath)) {
+ return NextResponse.json({ error: 'File does not exist' }, { status: 404 });
+ }
+ const content = fs.readFileSync(filePath, 'utf8');
+ return new NextResponse(content, { status: 200 });
+}
\ No newline at end of file
diff --git a/src/app/api/admin/posts/route.ts b/src/app/api/admin/posts/route.ts
index b08eea0..329920b 100644
--- a/src/app/api/admin/posts/route.ts
+++ b/src/app/api/admin/posts/route.ts
@@ -63,4 +63,26 @@ export async function PATCH(request: Request) {
{ status: 500 }
);
}
+}
+
+export async function PUT(request: Request) {
+ try {
+ const body = await request.json();
+ const { slug, path: folderPath, content } = body;
+ if (!slug || typeof content !== 'string') {
+ return NextResponse.json({ error: 'Missing slug or content' }, { status: 400 });
+ }
+ // Compute file path
+ const filePath = folderPath && folderPath.trim() !== ''
+ ? path.join(postsDirectory, folderPath, `${slug}.md`)
+ : path.join(postsDirectory, `${slug}.md`);
+ if (!fs.existsSync(filePath)) {
+ return NextResponse.json({ error: 'File does not exist' }, { status: 404 });
+ }
+ fs.writeFileSync(filePath, content, 'utf8');
+ return NextResponse.json({ success: true });
+ } catch (error) {
+ console.error('Error editing post:', error);
+ return NextResponse.json({ error: 'Error editing post' }, { status: 500 });
+ }
}
\ No newline at end of file