|
1 | 1 | ---
|
2 |
| -import { type CollectionEntry, getCollection } from "astro:content"; |
| 2 | +import { getCollection } from "astro:content"; |
3 | 3 | import TagPosts from "@layouts/TagPosts.astro";
|
4 | 4 | import getUniqueTags from "@utils/getUniqueTags";
|
5 | 5 | import getPostsByTag from "@utils/getPostsByTag";
|
6 |
| -import getPageNumbers from "@utils/getPageNumbers"; |
7 |
| -import getPagination from "@utils/getPagination"; |
| 6 | +import type { GetStaticPathsOptions } from "astro"; |
| 7 | +import { SITE } from "@config"; |
8 | 8 |
|
9 |
| -export interface Props { |
10 |
| - post: CollectionEntry<"blog">; |
11 |
| - tag: string; |
12 |
| - tagName: string; |
13 |
| -} |
14 |
| -
|
15 |
| -export async function getStaticPaths() { |
| 9 | +export async function getStaticPaths({ paginate }: GetStaticPathsOptions) { |
16 | 10 | const posts = await getCollection("blog");
|
17 |
| -
|
18 | 11 | const tags = getUniqueTags(posts);
|
19 | 12 |
|
20 | 13 | return tags.flatMap(({ tag, tagName }) => {
|
21 | 14 | const tagPosts = getPostsByTag(posts, tag);
|
22 |
| - const totalPages = getPageNumbers(tagPosts.length); |
23 | 15 |
|
24 |
| - return totalPages.map(page => ({ |
25 |
| - params: { tag, page }, |
26 |
| - props: { tag, tagName }, |
27 |
| - })); |
| 16 | + return paginate(tagPosts, { |
| 17 | + params: { tag }, |
| 18 | + props: { tagName }, |
| 19 | + pageSize: SITE.postPerPage, |
| 20 | + }); |
28 | 21 | });
|
29 | 22 | }
|
30 | 23 |
|
31 |
| -const { page } = Astro.params; |
32 |
| -const { tag, tagName } = Astro.props; |
33 |
| -
|
34 |
| -const posts = await getCollection("blog", ({ data }) => !data.draft); |
35 |
| -
|
36 |
| -const postsByTag = getPostsByTag(posts, tag); |
37 |
| -
|
38 |
| -const pagination = getPagination({ |
39 |
| - posts: postsByTag, |
40 |
| - page, |
41 |
| -}); |
| 24 | +const params = Astro.params; |
| 25 | +const { tag } = params; |
| 26 | +const { page, tagName } = Astro.props; |
42 | 27 | ---
|
43 | 28 |
|
44 |
| -<TagPosts {...pagination} {tag} {tagName} /> |
| 29 | +<TagPosts {page} {tag} {tagName} /> |
0 commit comments