Skip to content

Commit

Permalink
feat: fix generate static params
Browse files Browse the repository at this point in the history
  • Loading branch information
artabr committed Dec 2, 2024
1 parent c78d2e0 commit bc6c380
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 12 deletions.
14 changes: 10 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ const path = require('path');
/** @type {import('next').NextConfig} */
const nextConfig = {
sassOptions: {
includePaths: [path.join(__dirname, 'src')]
includePaths: [path.join(__dirname, 'src')],
},
experimental: {
scrollRestoration: false
scrollRestoration: false,
},
output: 'export',
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
images: {
unoptimized: true
}
unoptimized: true,
},
};

module.exports = nextConfig;
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"@total-typescript/ts-reset": "^0.6.1",
"@types/glob": "^8.1.0",
"@types/node": "20.2.5",
"@types/react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ export default async function Pages({
export async function generateStaticParams() {
const blogs = await getBlogs();

return getPageNumbers(blogs.posts.length)
.slice(1)
.map((page) => ({
return blogs.categories.flatMap((category) => {
const postsByCategory = blogs.posts.filter((post) =>
post.categories?.includes(category),
);
const pageNumbers = getPageNumbers(postsByCategory.length);

return pageNumbers.slice(1).map((page) => ({
category,
page,
}));
});
}
10 changes: 7 additions & 3 deletions src/app/blog/(taxonomies)/tags/[tag]/pages/[page]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export default async function Pages({
export async function generateStaticParams() {
const blogs = await getBlogs();

return getPageNumbers(blogs.posts.length)
.slice(1)
.map((page) => ({
return blogs.tags.flatMap((tag) => {
const postsByTag = blogs.posts.filter((post) => post.tags?.includes(tag));
const pageNumbers = getPageNumbers(postsByTag.length);

return pageNumbers.slice(1).map((page) => ({
tag,
page,
}));
});
}
7 changes: 5 additions & 2 deletions src/lib/fetch-utils/getBlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export const getBlogs = async () => {

const siteCategories = [
...new Set(postsMetadata.flatMap((post) => post.categories)),
];
const siteTags = [...new Set(postsMetadata.flatMap((post) => post.tags))];
].filter(Boolean);

const siteTags = [
...new Set(postsMetadata.flatMap((post) => post.tags)),
].filter(Boolean);

return {
posts: postsMetadata,
Expand Down
2 changes: 2 additions & 0 deletions src/reset.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Do not add any other lines of code to this file!
import '@total-typescript/ts-reset';

0 comments on commit bc6c380

Please sign in to comment.