I have a small blog in next js with a few blogposts. The blogposts are accessed through the file system.
What I want to do: Statically pre-render the blogposts. Before I would use getStaticProps and getStaticPaths like this:
export async function getStaticProps(context) {
const { params } = context;
const { slug } = params;
const postData = getPostData(slug);
return {
props: {
post: postData,
},
revalidate: 600,
};
}
export async function getStaticPaths() {
const postFilenames = getPostsFiles();
const slugs = postFilenames.map((fileName) => fileName.replace(/.md$/, ''));
return {
paths: slugs.map((slug) => ({ params: { slug } })),
fallback: false,
};
}
What is the equivalent with app based routing?
i find example here:
https://nextjs.org/docs/app/api-reference/functions/generate-static-params#generate-only-a-subset-of-params
but I struggle to translate it to this new code. Also – my posts are imported from file system so it feels wrong to use fetch.