How to build page for new posts
Answered
David posted this in #help-forum
DavidOP
Hi, If I have new posts regularly in a blog site, how nextjs can build new page for the new posts? Currently, I have to trigger build manually to build new post pages
Answered by ᴉuɐpɹɐɐ
You'd need to use generateStaticParams to generate the routes that will be available during build-time, and then
Missing route => routes thats not generated build time such as new articles and posts and et cetera
export const dynamicParams set to true. This will enable missing routes to be generated at request timeMissing route => routes thats not generated build time such as new articles and posts and et cetera
24 Replies
Polar bear
Could you elaborate? Are you using slug?
@Polar bear Could you elaborate? Are you using slug?
DavidOP
sorry I can't reproduce but the idea is nextjs built post/a, post/b. the data get from CMS
then I create a new post in CMS
this time, post/c doesn't exist
I have to rebuild the app "next build"
can you get it?
Stony gall
you can create dynamic routes where you can take a post name from params and display the content based on it, or if a post with that name does not exist, return some error status like NotFound
@David Hi, If I have new posts regularly in a blog site, how nextjs can build new page for the new posts? Currently, I have to trigger build manually to build new post pages
New Zealand
you can do something like:
// app/post/[...slug]/page.tsx
const Page = async ({ params: { slug } }: { params: { slug: string; } }) => {
const blogPost = await fetchBlog(slug);
return <>{blog.content}</>;
}
export default Page;DavidOP
I forgot the important part
We must have a post list
This post list is CSR, right?
If the post page is dynamic, it can't be SEO
@David If the post page is dynamic, it can't be SEO
New Zealand
it will SEO. you could use this
DavidOP
I got it, thank you guys
@New Zealand you can do something like:
ts
// app/post/[...slug]/page.tsx
const Page = async ({ params: { slug } }: { params: { slug: string; } }) => {
const blogPost = await fetchBlog(slug);
return <>{blog.content}</>;
}
export default Page;
Reddish carpenter ant
Thank you very much, was just doing EXACTLY the same - where in the documentation is this, mind giving me a link please? Or is NextJS docs THAT bad?
I haven't seen this anywhere, of this being injected like this, not stackoverflow, not chatgpt, anywhere. Nor did I found this in the docs - but mayeb I'm just a bad reader xd
New Zealand
it’s in the docs
Hi, If I have new posts regularly in a blog site, how nextjs can build new page for the new posts? Currently, I have to trigger build manually to build new post pages
If you set up ISR correctly, you can generate pages at request time without it being generated at build time, and still have it static.
You'd need to use generateStaticParams to generate the routes that will be available during build-time, and then
Missing route => routes thats not generated build time such as new articles and posts and et cetera
export const dynamicParams set to true. This will enable missing routes to be generated at request timeMissing route => routes thats not generated build time such as new articles and posts and et cetera
Answer
DavidOP
Yeah, thank you
@New Zealand it’s in the docs
Reddish carpenter ant
Thanks, must have been sleep deprived xd