refactor: v2
This commit is contained in:
@@ -1,36 +1,34 @@
|
||||
---
|
||||
import Layout from "@/layouts/Layout.astro";
|
||||
import type { Post } from "@/types/post";
|
||||
import { createHttp } from "@/lib/request";
|
||||
import { metadata } from "@/consts.ts";
|
||||
import IndexView from "@/components/IndexView.astro";
|
||||
import {siteConfig} from "@/consts.ts";
|
||||
import {createHttp} from "@/lib/request.ts";
|
||||
import type {Post} from "@/types";
|
||||
import IndexPage from "@/components/IndexPage.astro";
|
||||
const {page} = Astro.params;
|
||||
|
||||
const { page } = Astro.params;
|
||||
const pageInt = Number(page);
|
||||
|
||||
if (isNaN(Number(page))) {
|
||||
if (isNaN(pageInt) || pageInt <= 1) {
|
||||
return Astro.redirect("/");
|
||||
}
|
||||
|
||||
const {postPageSize,description} = siteConfig;
|
||||
|
||||
const http = createHttp(Astro.request.headers);
|
||||
|
||||
const { list, total } = await http.get<ApiPageResponse<Post>>("posts", {
|
||||
const {list, total} = await http.get<ApiPageResponse<Post>>("posts", {
|
||||
searchParams: {
|
||||
page,
|
||||
page_size: metadata.postPageSize,
|
||||
page: pageInt,
|
||||
page_size: postPageSize,
|
||||
},
|
||||
});
|
||||
const totalPage = Math.ceil(total / postPageSize);
|
||||
|
||||
const totalPage = Math.ceil(total / metadata.postPageSize);
|
||||
|
||||
if (totalPage < Number(page)) {
|
||||
if (totalPage < pageInt) {
|
||||
return Astro.redirect("/404");
|
||||
}
|
||||
---
|
||||
|
||||
<Layout description="天若有情天亦老,人间正道是沧桑。" title="博客首页">
|
||||
<IndexView
|
||||
posts={list}
|
||||
page={Number(page)}
|
||||
totalPage={totalPage}
|
||||
/>
|
||||
<Layout title="博客首页" description={description}>
|
||||
<IndexPage page={pageInt} totalPage={totalPage} posts={list}/>
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user