Update package-lock.json with new SWC binaries for various platforms; enhance Admin and Manage pages with folder path display and drag-and-drop functionality for posts, including move post API integration.
This commit is contained in:
@@ -8,7 +8,7 @@ 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;
|
||||
const { title, date, tags, summary, content, path: folderPath } = body;
|
||||
|
||||
// Create slug from title
|
||||
const slug = title
|
||||
@@ -25,8 +25,15 @@ export async function POST(request: Request) {
|
||||
author: process.env.NEXT_PUBLIC_BLOG_OWNER + "'s" || 'Anonymous',
|
||||
});
|
||||
|
||||
// Write the file
|
||||
const filePath = path.join(postsDirectory, `${slug}.md`);
|
||||
// Write the file in the correct folder if provided
|
||||
let filePath;
|
||||
if (folderPath && folderPath.trim() !== '') {
|
||||
filePath = path.join(postsDirectory, folderPath, `${slug}.md`);
|
||||
// Ensure the directory exists
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
} else {
|
||||
filePath = path.join(postsDirectory, `${slug}.md`);
|
||||
}
|
||||
fs.writeFileSync(filePath, frontmatter);
|
||||
|
||||
return NextResponse.json({ success: true, slug });
|
||||
|
||||
Reference in New Issue
Block a user