Refactor navigation links to use Next.js routing and improve post handling
- Updated AboutButton to navigate to the about page using Next.js router. - Changed HeaderButtons and MobileNav to link directly to the about page. - Modified Home component to exclude the 'about' post from the posts list. - Added a helper function to strip YAML frontmatter from post summaries. - Enhanced API routes to handle reading and writing markdown files for posts.
This commit is contained in:
@@ -19,6 +19,13 @@ export async function GET(
|
||||
);
|
||||
if (rustResult.status === 0 && rustResult.stdout) {
|
||||
const post = JSON.parse(rustResult.stdout);
|
||||
const fs = require('fs');
|
||||
const filePath = path.join(postsDirectory, slugPath + '.md');
|
||||
let raw = '';
|
||||
try {
|
||||
raw = fs.readFileSync(filePath, 'utf8');
|
||||
} catch {}
|
||||
post.raw = raw;
|
||||
post.createdAt = post.created_at;
|
||||
delete post.created_at;
|
||||
return NextResponse.json(post);
|
||||
@@ -33,4 +40,20 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request, { params }: { params: { slug: string[] | string } }) {
|
||||
try {
|
||||
const { markdown } = await request.json();
|
||||
if (typeof markdown !== 'string') {
|
||||
return NextResponse.json({ error: 'Invalid markdown' }, { status: 400 });
|
||||
}
|
||||
const slugArr = Array.isArray(params.slug) ? params.slug : [params.slug];
|
||||
const slugPath = slugArr.join('/');
|
||||
const filePath = path.join(postsDirectory, slugPath + '.md');
|
||||
require('fs').writeFileSync(filePath, markdown, 'utf8');
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ error: 'Error saving file', details: error instanceof Error ? error.message : 'Unknown error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user