diff --git a/src/api/index.ts b/src/api/index.ts index 272b9621..75b82dbe 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -7,12 +7,13 @@ import { Categories, Post, PostList, - SpecificPostsList, + SpecificPostListRaw, Tags } from '@/models/Post.class' import { Article, Page } from '@/models/Article.class' import { Statistic } from '@/models/Statistic.class' import { SearchIndexes } from '@/models/Search.class' +import { paginator } from '@/utils' // GET /api/site.json export async function fetchHexoConfig(): Promise> { @@ -35,16 +36,35 @@ export async function fetchArchivesList( // GET /api/tags/:TagName.json export async function fetchPostsListByTag( - tagName: string + tagName: string, + page: number, + pageSize: number ): Promise> { - return request.get(`/tags/${tagName}.json`) + const response = await request.get( + `/tags/${tagName}.json` + ) + + response.data.postlist = paginator(response.data.postlist, page, pageSize) + + return response } // GET /api/categories/:slug.json export async function fetchPostsListByCategory( - categoryName: string -): Promise> { - return request.get(`/categories/${categoryName}.json`) + categoryName: string, + page: number, + pageSize: number +) { + const response = await request.get( + `/categories/${categoryName}.json` + ) + + response.data.pageSize = pageSize + response.data.total = response.data.postlist.length + response.data.pageCount = Math.ceil(response.data.postlist.length / pageSize) + response.data.postlist = paginator(response.data.postlist, page, pageSize) + + return response } // GET /api/articles/:Slug.json diff --git a/src/components/Link/LinkCategoryList.vue b/src/components/Link/LinkCategoryList.vue index 82df30c3..c2be993c 100644 --- a/src/components/Link/LinkCategoryList.vue +++ b/src/components/Link/LinkCategoryList.vue @@ -2,13 +2,13 @@