mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
Update post/index page to display page 1
This commit is contained in:
+10
-20
@@ -1,29 +1,19 @@
|
||||
---
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import Main from "@layouts/Main.astro";
|
||||
import Card from "@components/Card";
|
||||
import Posts from "@layouts/Posts.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import getPageNumbers from "@utils/getPageNumbers";
|
||||
import type { Frontmatter } from "@utils/types";
|
||||
|
||||
const posts = await Astro.glob<Frontmatter>("../../contents/*.md");
|
||||
|
||||
const sortedPosts = getSortedPosts(posts);
|
||||
|
||||
const totalPages = getPageNumbers(posts.length);
|
||||
|
||||
const paginatedPosts = sortedPosts.slice(
|
||||
0,
|
||||
import.meta.env.PUBLIC_POST_PER_PAGE
|
||||
);
|
||||
---
|
||||
|
||||
<Layout title={`Posts | ${import.meta.env.PUBLIC_SITE_TITLE}`}>
|
||||
<Header activeNav="posts" />
|
||||
<Main pageTitle="Posts" pageDesc="All the articles I've posted.">
|
||||
<ul>
|
||||
{
|
||||
sortedPosts.map(({ frontmatter }) => {
|
||||
return (
|
||||
<Card href={`/posts/${frontmatter.slug}`} post={frontmatter} />
|
||||
);
|
||||
})
|
||||
}
|
||||
</ul>
|
||||
</Main>
|
||||
<Footer />
|
||||
</Layout>
|
||||
<Posts posts={paginatedPosts} pageNum={1} totalPages={totalPages.length} />
|
||||
|
||||
Reference in New Issue
Block a user