fix: fix cr bugs from coderabbit
This commit is contained in:
parent
d391d35e26
commit
6a4f0575c4
@ -21,7 +21,7 @@ export function generateStaticParams() {
|
||||
allPosts.filter(
|
||||
(post) =>
|
||||
post.locale === locale &&
|
||||
post.categories.some((cat) => cat && cat.slug !== category.slug)
|
||||
post.categories.some((cat) => cat && cat.slug === category.slug)
|
||||
).length / websiteConfig.blog.paginationSize
|
||||
);
|
||||
for (let page = 2; page <= totalPages; page++) {
|
||||
@ -54,7 +54,7 @@ interface BlogCategoryPageProps {
|
||||
params: Promise<{
|
||||
locale: Locale;
|
||||
slug: string;
|
||||
page: number;
|
||||
page: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ export default async function BlogCategoryPage({
|
||||
params,
|
||||
}: BlogCategoryPageProps) {
|
||||
const { locale, slug, page } = await params;
|
||||
const currentPage = page;
|
||||
const currentPage = Number(page);
|
||||
const category = allCategories.find(
|
||||
(category) => category.slug === slug && category.locale === locale
|
||||
);
|
||||
|
@ -1,9 +1,10 @@
|
||||
import type { Post } from 'content-collections';
|
||||
import EmptyGrid from '../shared/empty-grid';
|
||||
import CustomPagination from '../shared/pagination';
|
||||
import BlogGrid from './blog-grid';
|
||||
|
||||
interface BlogListWithPaginationProps {
|
||||
posts: any[];
|
||||
interface BlogGridWithPaginationProps {
|
||||
posts: Post[];
|
||||
totalPages: number;
|
||||
routePrefix: string;
|
||||
}
|
||||
@ -12,7 +13,7 @@ export default function BlogGridWithPagination({
|
||||
posts,
|
||||
totalPages,
|
||||
routePrefix,
|
||||
}: BlogListWithPaginationProps) {
|
||||
}: BlogGridWithPaginationProps) {
|
||||
return (
|
||||
<div>
|
||||
{posts.length === 0 && <EmptyGrid />}
|
||||
@ -21,7 +22,7 @@ export default function BlogGridWithPagination({
|
||||
<BlogGrid posts={posts} />
|
||||
<div className="mt-8 flex items-center justify-center">
|
||||
<CustomPagination
|
||||
routePreix={routePrefix}
|
||||
routePrefix={routePrefix}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
</div>
|
||||
|
@ -21,12 +21,12 @@ function getCurrentPageFromPath(pathname: string): number {
|
||||
|
||||
type CustomPaginationProps = {
|
||||
totalPages: number;
|
||||
routePreix: string;
|
||||
routePrefix: string;
|
||||
};
|
||||
|
||||
export default function CustomPagination({
|
||||
totalPages,
|
||||
routePreix,
|
||||
routePrefix,
|
||||
}: CustomPaginationProps) {
|
||||
const router = useLocaleRouter();
|
||||
const pathname = useLocalePathname();
|
||||
@ -36,10 +36,10 @@ export default function CustomPagination({
|
||||
const pageNum = Number(page);
|
||||
if (pageNum === 1) {
|
||||
// Go to /blog or /blog/category/[slug] for page 1
|
||||
router.push(routePreix);
|
||||
router.push(routePrefix);
|
||||
} else {
|
||||
// Go to /blog/page/x or /blog/category/[slug]/page/x
|
||||
router.push(`${routePreix}/page/${pageNum}`);
|
||||
router.push(`${routePrefix}/page/${pageNum}`);
|
||||
}
|
||||
};
|
||||
|
||||
@ -134,8 +134,3 @@ const generatePagination = (currentPage: number, totalPages: number) => {
|
||||
totalPages,
|
||||
];
|
||||
};
|
||||
|
||||
function normalizePath(path: string) {
|
||||
// Remove duplicated locale prefix, e.g. /zh/zh/blog => /zh/blog
|
||||
return path.replace(/^(\/\w{2,3})(?:\1)+/, '$1');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user