fix: notFound() on missing post, await params for Next.js 15

This commit is contained in:
2026-03-31 02:39:33 +02:00
parent b2a611ce5b
commit 7faaac2081
2 changed files with 7 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import readingTime from 'reading-time';
import { notFound } from 'next/navigation';
const postsDirectory = path.join(process.cwd(), 'posts');
@@ -90,6 +91,7 @@ export function getAllPostIds() {
export async function getPostData(id: string): Promise<PostData> {
const fullPath = path.join(postsDirectory, `${id}.mdx`);
if (!fs.existsSync(fullPath)) notFound();
const fileContents = fs.readFileSync(fullPath, 'utf8');
const matterResult = matter(fileContents);
const stats = readingTime(matterResult.content);