From 8e3e1d583446fc34356400c6c1217ba0cc512a0a Mon Sep 17 00:00:00 2001 From: KazooTTT Date: Wed, 5 Feb 2025 23:02:29 +0800 Subject: [PATCH] feat: show counts --- src/components/note/Note.astro | 12 ++++++++---- src/pages/notes/[...page].astro | 16 +++++++++++----- src/pages/posts/[...page].astro | 8 +++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index f4d9d90..0997c83 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -6,9 +6,10 @@ import GiscusComment from "@/components/componentsBefore/GiscusComment"; type Props = Polymorphic<{ as: Tag }> & { note: CollectionEntry<"note">; isPreview?: boolean | undefined; + index?: number; }; -const { as: Tag = "div", note, isPreview = false } = Astro.props; +const { as: Tag = "div", note, isPreview = false, index } = Astro.props; const { Content } = await render(note); const dateTimeOptions: Intl.DateTimeFormatOptions = note.data.date_created ? { @@ -37,9 +38,12 @@ const date = note.data.date_created ?? note.data.date; { isPreview ? ( - - {note.data.title} - + <> + {index + 1}.{" "} + + {note.data.title} + + ) : ( <>{note.data.title} ) diff --git a/src/pages/notes/[...page].astro b/src/pages/notes/[...page].astro index fdc5af9..e8175ad 100644 --- a/src/pages/notes/[...page].astro +++ b/src/pages/notes/[...page].astro @@ -10,15 +10,20 @@ import { Icon } from "astro-icon/components"; export const getStaticPaths = (async ({ paginate }) => { const MAX_NOTES_PER_PAGE = 10; const allNotes = await getCollection("note"); - return paginate(allNotes.sort(collectionDateSort), { pageSize: MAX_NOTES_PER_PAGE }); + const notesCount = allNotes.length; + return paginate(allNotes.sort(collectionDateSort), { + pageSize: MAX_NOTES_PER_PAGE, + props: { notesCount }, + }); }) satisfies GetStaticPaths; interface Props { page: Page>; uniqueTags: string[]; + notesCount: number; } -const { page } = Astro.props; +const { page, notesCount } = Astro.props; const meta = { description: "Read my collection of notes", @@ -44,16 +49,17 @@ const paginationProps = {

- Notes + Notes({notesCount}) + RSS feed

    { - page.data.map((note) => ( + page.data.map((note, index) => (
  • - +
  • )) } diff --git a/src/pages/posts/[...page].astro b/src/pages/posts/[...page].astro index 9e030e1..bf8c745 100644 --- a/src/pages/posts/[...page].astro +++ b/src/pages/posts/[...page].astro @@ -15,9 +15,10 @@ export const getStaticPaths = (async ({ paginate }) => { const allPosts = await getAllPosts(); const uniqueTags = getUniqueTags(allPosts).slice(0, MAX_TAGS); const uniqueCategories = getUniqueCategories(allPosts).slice(0, MAX_CATEGORIES); + const postsCount = allPosts.length; return paginate(allPosts.sort(collectionDateSort), { pageSize: MAX_POSTS_PER_PAGE, - props: { uniqueTags, uniqueCategories }, + props: { uniqueTags, uniqueCategories, postsCount }, }); }) satisfies GetStaticPaths; @@ -25,9 +26,10 @@ interface Props { page: Page>; uniqueTags: string[]; uniqueCategories: string[]; + postsCount: number; } -const { page, uniqueTags, uniqueCategories } = Astro.props; +const { page, uniqueTags, uniqueCategories, postsCount } = Astro.props; const meta = { description: "Read my collection of posts and the things that interest me", @@ -55,7 +57,7 @@ const descYearKeys = Object.keys(groupedByYear).sort((a, b) => +b - +a);
    -

    Posts

    +

    Posts({postsCount})

    RSS feed