diff --git a/src/components/note/Note.astro b/src/components/note/Note.astro index da39828..dc0289e 100644 --- a/src/components/note/Note.astro +++ b/src/components/note/Note.astro @@ -6,13 +6,15 @@ import GiscusComment from "@/components/componentsBefore/GiscusComment"; import ArticleContainer from "../ArticleContainer.astro"; import ShareButtons from "../ShareButtons.astro"; import ContentFooter from "../ContentFooter.astro"; +import { cn } from "@/utils/tailwind"; type Props = Polymorphic<{ as: Tag }> & { note: CollectionEntry<"note">; isPreview?: boolean | undefined; index?: number; + enableLineClamp?: boolean; }; -const { as: Tag = "div", note, isPreview = false, index } = Astro.props; +const { as: Tag = "div", note, isPreview = false, index, enableLineClamp = false } = Astro.props; const { Content } = await render(note); const dateTimeOptions: Intl.DateTimeFormatOptions = note.data.date_created ? { @@ -36,15 +38,18 @@ if (modifiedDate && modifiedDate.toDateString() === date.toDateString()) { --- { isPreview ? ( <> - {index ? `${index + 1}.` : ""} + {index !== undefined && index !== null ? `${index + 1}.` : ""} {note.data.title} @@ -66,7 +71,12 @@ if (modifiedDate && modifiedDate.toDateString() === date.toDateString()) { }
-
+
p:last-of-type]:mb-0", + enableLineClamp && "line-clamp-4" + )} + >
diff --git a/src/pages/index.astro b/src/pages/index.astro index 15b6a1c..bd7b19c 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -15,7 +15,7 @@ const allPostsByDate = allPosts .slice(0, MAX_POSTS) as CollectionEntry<"post">[]; // Notes -const MAX_NOTES = 5; +const MAX_NOTES = 6; const allNotes = await getCollection("note"); const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES); --- @@ -44,10 +44,10 @@ const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);

Notes

-
    +
      {latestNotes.map((note) => (
    • - +
    • ))}
    diff --git a/src/pages/notes/[...page].astro b/src/pages/notes/[...page].astro index 796bd12..4c4c9ff 100644 --- a/src/pages/notes/[...page].astro +++ b/src/pages/notes/[...page].astro @@ -59,17 +59,24 @@ function calculateIndex(index: number, page: Page>) {
diff --git a/src/pages/notes/list/[...page].astro b/src/pages/notes/list/[...page].astro index 3529f7b..e0ebe87 100644 --- a/src/pages/notes/list/[...page].astro +++ b/src/pages/notes/list/[...page].astro @@ -1,53 +1,33 @@ --- -import { getCollection, type CollectionEntry } from "astro:content"; +import { type CollectionEntry, getCollection } from "astro:content"; import Pagination from "@/components/Paginator.astro"; -import PostPreview from "@/components/blog/PostPreview.astro"; +import Note from "@/components/note/Note.astro"; import PageLayout from "@/layouts/Base.astro"; -import { collectionDateSort } from "@/utils/date"; +import { collectionModifiedDateSort } from "@/utils/date"; import type { GetStaticPaths, Page } from "astro"; import { Icon } from "astro-icon/components"; -// 添加新的类型定义 -type NoteEntry = CollectionEntry<"note">; - -// 创建一个新的groupNotesByYear函数 -function groupNotesByYear(notes: NoteEntry[]) { - return notes.reduce( - (acc, note) => { - const year = note.data.date.getFullYear().toString(); - acc[year] = acc[year] || []; - acc[year].push(note); - return acc; - }, - {} as Record - ); -} - export const getStaticPaths = (async ({ paginate }) => { - const MAX_POSTS_PER_PAGE = 10; + const MAX_NOTES_PER_PAGE = 10; const allNotes = await getCollection("note"); - const postsCount = allNotes.length; - return paginate(allNotes.sort(collectionDateSort), { - pageSize: MAX_POSTS_PER_PAGE, - props: { postsCount }, + const notesCount = allNotes.length; + return paginate(allNotes.sort(collectionModifiedDateSort), { + pageSize: MAX_NOTES_PER_PAGE, + props: { notesCount }, }); }) satisfies GetStaticPaths; interface Props { page: Page>; uniqueTags: string[]; - uniqueCategories: string[]; - postsCount: number; + notesCount: number; } -const { page, postsCount } = Astro.props; - -// 添加默认布局状态 -const defaultLayout = "list"; // 或 "grid" +const { page, notesCount } = Astro.props; const meta = { - description: "Read my collection of posts and the things that interest me", - title: "Posts", + description: "Read my collection of notes", + title: "Notes", }; const paginationProps = { @@ -65,78 +45,38 @@ const paginationProps = { }), }; -// 使用新的groupNotesByYear函数替换原来的groupPostsByYear -const groupedByYear = groupNotesByYear(page.data); -const descYearKeys = Object.keys(groupedByYear).sort((a, b) => +b - +a); +function calculateIndex(index: number, page: Page>) { + return index + page.start; +} --- -
-

Notes({postsCount})

- - RSS feed - -
- see the preview -
-
-
+
+

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

+
{ - descYearKeys.map((yearKey) => ( -
-

- Posts in - {yearKey} -

-
    - {groupedByYear[yearKey]?.map((p) => ( -
  • - -
  • - ))} -
-
+ page.data.map((note, index) => ( + )) } -
-
+ + - -