I have 3 blog categories which I need to paginate static pages for each of them . The problem is the number of pages may vary and I can't get access to anything on what category needs to be fetched in getStaticPaths .
The project folder structure is like this :

My code is like this :
export const getStaticPaths: GetStaticPaths = async (props) => {
// const { category } = props.params; // Cant Access to dynamic category name from the url
const blogs = await client.getEntries({
content_type: "blog",
// "fields.category": category, // Cant Access to dynamic category name from the url
});
let pages;
const howmany = blogs.total / 12;
pages = Math.ceil(howmany / 1) * 1;
let paths = [];
for (var i = 0; i < pages; i++) {
paths.push({
params: { page: `${i + 1}` },
});
}
return {
paths ,
fallback: "blocking",
};
};
export const getStaticProps: GetStaticProps = async ({ params }) => {
const { category, page } = params;
const limit = 2;
let skip;
if (JSON.parse(page) === 1) {
skip = 0;
} else {
skip = JSON.parse(page) * limit - limit;
}
const blogs = await client.getEntries({
content_type: "blog",
limit: limit,
skip: skip,
"fields.category": category,
});
return {
props: {
page: JSON.parse(page),
blogs: blogs.items,
},
revalidate: 1,
};
};
I need to get access to dynamic category string from url in getStaticPaths so I can get the exact number of blogposts for that specific category but couldn't have access to anything at all .
How can I fix this problem ? Is there a workaround to fix this ?
Thanks in advance .
I solved the issue with the help of Ivan atias Christian Hagelid and generated all categories pages in getStaticPaths and returned the final path like this :
let paths = [];
newCategories.forEach((eachCategory: any) => {
let pages;
const howmany = eachCategory.posts.length / limit;
pages = Math.ceil(howmany / 1) * 1;
for (var i = 0; i < pages; i++) {
paths.push({
params: { page: `${i + 1}`, category: eachCategory.category },
});
}
});
return {
paths,
fallback: false,
};