35 lines
848 B
Plaintext
35 lines
848 B
Plaintext
---
|
|
import Layout from "@/layouts/Layout.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 pageInt = 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", {
|
|
searchParams: {
|
|
page: pageInt,
|
|
page_size: postPageSize,
|
|
},
|
|
});
|
|
const totalPage = Math.ceil(total / postPageSize);
|
|
|
|
if (totalPage < pageInt) {
|
|
return Astro.redirect("/404");
|
|
}
|
|
---
|
|
|
|
<Layout title="博客首页" description={description}>
|
|
<IndexPage page={pageInt} totalPage={totalPage} posts={list}/>
|
|
</Layout>
|