Skip to content

Commit a6adcd8

Browse files
committed
feat: implement pagination for tag articles with new nested route
1 parent 25a28f3 commit a6adcd8

2 files changed

Lines changed: 524 additions & 15 deletions

File tree

src/pages/articles/tag/[tag].astro

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,11 @@ import ArwesBackground from '../../../components/ArwesBackground';
99
import Pagination from '../../../components/Pagination.astro';
1010
import { SITE_DESCRIPTION, SITE_TITLE } from '../../../consts';
1111
12-
export async function getStaticPaths({ paginate }: any) {
13-
const posts = await getCollection('blog');
14-
const tags = [...new Set(posts.flatMap(post => post.data.tags))] as string[];
15-
16-
return tags.flatMap((tag) => {
17-
const tagPosts = posts.filter(post =>
18-
post.data.tags.includes(tag)
19-
).sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
20-
21-
return paginate(tagPosts, {
22-
params: { tag: tag.toLowerCase().replace(/\s+/g, '-') },
23-
props: { tagName: tag },
24-
pageSize: 6
25-
});
26-
});
12+
export async function getStaticPaths() {
13+
// This file was previously used for tag pages, but pagination now uses
14+
// the nested route at `src/pages/articles/tag/[tag]/[page].astro`.
15+
// Return no paths here to avoid duplicate/contradictory routes.
16+
return [];
2717
}
2818
2919
const { page, tagName }: any = Astro.props;

0 commit comments

Comments
 (0)