fix: url `/page/1` -> `/`, `/page/2` -> `/2`

This commit is contained in:
saicaca 2024-02-18 18:10:12 +08:00 committed by saica.go
parent bd17b39fd2
commit 90070d06c1
4 changed files with 23 additions and 48 deletions

View File

@ -70,9 +70,6 @@ export default defineConfig({
], ],
], ],
}, },
redirects: {
"/": "/page/1",
},
vite: { vite: {
plugins: [yaml()], plugins: [yaml()],
css: { css: {

22
src/pages/[...page].astro Normal file
View File

@ -0,0 +1,22 @@
---
import MainGridLayout from "../layouts/MainGridLayout.astro";
import PostCard from "../components/PostCard.astro";
import Pagination from "../components/control/Pagination.astro";
import {getSortedPosts} from "../utils/content-utils";
import {getPostUrlBySlug} from "../utils/url-utils";
import {PAGE_SIZE} from "../constants/constants";
import PostPage from "../components/PostPage.astro";
export async function getStaticPaths({ paginate }) {
const allBlogPosts = await getSortedPosts();
return paginate(allBlogPosts, { pageSize: PAGE_SIZE });
}
const {page} = Astro.props;
---
<MainGridLayout>
<PostPage page={page}></PostPage>
<Pagination class="mx-auto" page={page}></Pagination>
</MainGridLayout>

View File

@ -1,36 +0,0 @@
---
import MainGridLayout from "@layouts/MainGridLayout.astro";
import TitleCard from "@components/TitleCardNew.astro";
import Pagination from "@components/control/Pagination.astro";
import {getSortedPosts} from "@utils/content-utils";
import {getPostUrlBySlug} from "@utils/url-utils";
export async function getStaticPaths({ paginate }) {
const allBlogPosts = await getSortedPosts();
return paginate(allBlogPosts, { pageSize: 8 });
}
const {page} = Astro.props;
---
<MainGridLayout>
<div class="transition flex flex-col rounded-[var(--radius-large)] bg-[var(--card-bg)] py-1 md:py-0 md:bg-transparent md:gap-4 mb-4">
{page.data.map((entry: { data: { draft: boolean; title: string; tags: string[]; category: string; published: Date; image: string; description: string; }; slug: string; }) => {
return (
<TitleCard
entry={entry}
title={entry.data.title}
tags={entry.data.tags}
category={entry.data.category}
published={entry.data.published}
url={getPostUrlBySlug(entry.slug)}
image={entry.data.image}
description={entry.data.description}
draft={entry.data.draft}
></TitleCard>
);
})}
</div>
<Pagination class="mx-auto" page={page}></Pagination>
</MainGridLayout>

View File

@ -1,9 +1 @@
{ {}
"redirects": [
{
"source": "/",
"destination": "/page/1",
"statusCode": 307
}
]
}