diff --git a/src/pages/archive/[...page].astro b/src/pages/archive/[...page].astro
new file mode 100644
index 0000000..ac66baf
--- /dev/null
+++ b/src/pages/archive/[...page].astro
@@ -0,0 +1,109 @@
+---
+import Pagination from "@/components/Paginator.astro";
+import PostPreview from "@/components/blog/PostPreview.astro";
+import {
+ getAllCollectionPosts,
+ getUniqueCategories,
+ getUniqueTags,
+ groupPostsByYear,
+} from "@/data/post";
+import PageLayout from "@/layouts/Base.astro";
+import { collectionDateSort, getLatestUpdatedPost } from "@/utils/date";
+import type { GetStaticPaths, Page } from "astro";
+import { MAX_TAGS, MAX_CATEGORIES, MAX_POSTS_PER_PAGE, MAX_LATEST_POSTS } from "@/utils/constant";
+import type { AllItem } from "@/types";
+
+export const getStaticPaths = (async ({ paginate }) => {
+ const allPosts = await getAllCollectionPosts();
+ const uniqueTags = getUniqueTags(allPosts).slice(0, MAX_TAGS);
+ const uniqueCategories = getUniqueCategories(allPosts).slice(0, MAX_CATEGORIES);
+ const latestUpdatedPost = allPosts.sort(getLatestUpdatedPost).slice(0, MAX_LATEST_POSTS);
+ const postsCount = allPosts.length;
+ return paginate(allPosts.sort(collectionDateSort), {
+ pageSize: MAX_POSTS_PER_PAGE,
+ props: { uniqueTags, uniqueCategories, postsCount, latestUpdatedPost },
+ });
+}) satisfies GetStaticPaths;
+
+interface Props {
+ page: Page
;
+ uniqueTags: string[];
+ uniqueCategories: string[];
+ postsCount: number;
+ latestUpdatedPost: AllItem[];
+}
+
+const { page, postsCount, latestUpdatedPost } = Astro.props;
+
+const meta = {
+ description: "Read my collection of posts and the things that interest me",
+ title: "Posts",
+};
+
+const paginationProps = {
+ ...(page.url.prev && {
+ prevUrl: {
+ text: "← Previous Page",
+ url: page.url.prev,
+ },
+ }),
+ ...(page.url.next && {
+ nextUrl: {
+ text: "Next Page →",
+ url: page.url.next,
+ },
+ }),
+};
+
+const groupedByYear = groupPostsByYear(page.data);
+const descYearKeys = Object.keys(groupedByYear).sort((a, b) => +b - +a);
+---
+
+
+
+
Archive({postsCount})
+
+
+
+ {
+ descYearKeys.map((yearKey) => (
+
+
+ Posts in
+ {yearKey}
+
+
+ {groupedByYear[yearKey]?.map((p) => (
+ -
+
+
+ ))}
+
+
+ ))
+ }
+
+
+
+
+
diff --git a/src/pages/categories/index.astro b/src/pages/categories/index.astro
index 885a65f..5ca17dd 100644
--- a/src/pages/categories/index.astro
+++ b/src/pages/categories/index.astro
@@ -18,7 +18,7 @@ const meta = {
allCategories.map(([item, val]) => (
[];
+const allPostsByDate = allPosts.sort(collectionDateSort).slice(0, MAX_POSTS);
// Fixed to top Posts
const allFixedToTopPosts = await getAllFixedToTopPosts();
-const allFixedToTopPostsByDate = allFixedToTopPosts
- .sort(collectionDateSort)
- .slice(0, MAX_POSTS) as CollectionEntry<"post">[];
-
+const allFixedToTopPostsByDate = allFixedToTopPosts.sort(collectionDateSort).slice(0, MAX_POSTS);
+
// Notes
const MAX_NOTES = 6;
-const allNotes = await getCollection("note");
+const allNotes = await getAllNotes();
const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);
---
@@ -36,15 +31,15 @@ const latestNotes = allNotes.sort(collectionDateSort).slice(0, MAX_NOTES);
{
allFixedToTopPostsByDate.length > 0 && (
-
+
- {
- allFixedToTopPostsByDate.map((p) => (
- -
-
-
- ))
- }
+ {allFixedToTopPostsByDate.map((p) => (
+ -
+
+
+ ))}
)
diff --git a/src/pages/notes/[...page].astro b/src/pages/notes/[...page].astro
index 55f0712..4ccbc51 100644
--- a/src/pages/notes/[...page].astro
+++ b/src/pages/notes/[...page].astro
@@ -1,15 +1,16 @@
---
-import { type CollectionEntry, getCollection } from "astro:content";
import Pagination from "@/components/Paginator.astro";
import Note from "@/components/note/Note.astro";
import PageLayout from "@/layouts/Base.astro";
import { collectionDateSort } from "@/utils/date";
import type { GetStaticPaths, Page } from "astro";
import { Icon } from "astro-icon/components";
+import { getAllNotes } from "@/data/post";
+import type { NoteItem } from "@/types";
export const getStaticPaths = (async ({ paginate }) => {
const MAX_NOTES_PER_PAGE = 10;
- const allNotes = await getCollection("note");
+ const allNotes = await getAllNotes();
const notesCount = allNotes.length;
return paginate(allNotes.sort(collectionDateSort), {
pageSize: MAX_NOTES_PER_PAGE,
@@ -18,7 +19,7 @@ export const getStaticPaths = (async ({ paginate }) => {
}) satisfies GetStaticPaths;
interface Props {
- page: Page>;
+ page: Page;
uniqueTags: string[];
notesCount: number;
}
@@ -45,7 +46,7 @@ const paginationProps = {
}),
};
-function calculateIndex(index: number, page: Page>) {
+function calculateIndex(index: number, page: Page) {
return index + page.start;
}
---
@@ -60,11 +61,11 @@ function calculateIndex(index: number, page: Page>) {
flowpreview
-
+
{
page.data.map((note, index) => (
>) {
as="h2"
isPreview
index={calculateIndex(index, page)}
- enableLineClamp={true}
+ enableLineClamp={false}
/>
))
}
diff --git a/src/pages/notes/[...slug].astro b/src/pages/notes/[...slug].astro
index 4cbcdc9..7acca7d 100644
--- a/src/pages/notes/[...slug].astro
+++ b/src/pages/notes/[...slug].astro
@@ -1,14 +1,13 @@
---
-import { getCollection } from "astro:content";
-
import Note from "@/components/note/Note.astro";
import PageLayout from "@/layouts/Base.astro";
import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
import { siteConfig } from "@/site.config";
+import { getAllNotes } from "@/data/post";
// if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr
export const getStaticPaths = (async () => {
- const allNotes = await getCollection("note");
+ const allNotes = await getAllNotes();
return allNotes.map((note) => ({
params: { slug: note.id },
props: { note },
@@ -22,7 +21,7 @@ const { note } = Astro.props;
const meta = {
description:
note.data.description ||
- `Read about my note posted on ${siteConfig.title} (${siteConfig.description}) at ${note.data.date.toLocaleDateString()} by ${siteConfig.author}`,
+ `Read about my note posted on ${siteConfig.title} (${siteConfig.description}) at ${note.dateToCmp.toLocaleDateString()} by ${siteConfig.author}`,
title: note.data.title,
tags: note.data.tags.join(", "),
};
diff --git a/src/pages/notes/list/[...page].astro b/src/pages/notes/list/[...page].astro
deleted file mode 100644
index 62ad758..0000000
--- a/src/pages/notes/list/[...page].astro
+++ /dev/null
@@ -1,82 +0,0 @@
----
-import { type CollectionEntry, getCollection } from "astro:content";
-import Pagination from "@/components/Paginator.astro";
-import Note from "@/components/note/Note.astro";
-import PageLayout from "@/layouts/Base.astro";
-import { collectionDateSort } from "@/utils/date";
-import type { GetStaticPaths, Page } from "astro";
-import { Icon } from "astro-icon/components";
-
-export const getStaticPaths = (async ({ paginate }) => {
- const MAX_NOTES_PER_PAGE = 10;
- const allNotes = await getCollection("note");
- 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, notesCount } = Astro.props;
-
-const meta = {
- description: "Read my collection of notes",
- title: "Notes",
-};
-
-const paginationProps = {
- ...(page.url.prev && {
- prevUrl: {
- text: "← Previous Page",
- url: page.url.prev,
- },
- }),
- ...(page.url.next && {
- nextUrl: {
- text: "Next Page →",
- url: page.url.next,
- },
- }),
-};
-
-function calculateIndex(index: number, page: Page>) {
- return index + page.start;
-}
----
-
-
-
-
-
- {
- page.data.map((note, index) => (
-
- ))
- }
-
-
-
-
diff --git a/src/pages/notes/rss.xml.ts b/src/pages/notes/rss.xml.ts
index 7ef9b00..3b58bd1 100644
--- a/src/pages/notes/rss.xml.ts
+++ b/src/pages/notes/rss.xml.ts
@@ -1,12 +1,12 @@
+import { getAllNotes } from "@/data/post";
import { siteConfig } from "@/site.config";
import { collectionDateSort } from "@/utils/date";
import rss from "@astrojs/rss";
-import { getCollection } from "astro:content";
import MarkdownIt from "markdown-it";
import sanitizeHtml from "sanitize-html";
export const GET = async () => {
- const notes = await getCollection("note");
+ const notes = await getAllNotes();
const sortedNotes = notes.sort(collectionDateSort);
const parser = new MarkdownIt();
@@ -25,7 +25,7 @@ export const GET = async () => {
return {
title: post.data.title,
description: (post.data.description ?? "") + "\t" + tagStr,
- pubDate: post.data.date,
+ pubDate: post.dateToCmp,
link: `notes/${post.id}/`,
content: post.body
? sanitizeHtml(
diff --git a/src/pages/og-image/[...slug].png.ts b/src/pages/og-image/[...slug].png.ts
index 6c3b5e6..3c78c75 100644
--- a/src/pages/og-image/[...slug].png.ts
+++ b/src/pages/og-image/[...slug].png.ts
@@ -15,7 +15,7 @@ const ogOptions: SatoriOptions = {
name: "ZCOOLXiaoWei",
style: "normal",
weight: 400,
- }
+ },
],
height: 630,
width: 1200,
@@ -76,7 +76,7 @@ export async function getStaticPaths() {
.map((post) => ({
params: { slug: post.id },
props: {
- pubDate: post.data.date ?? post.data.date_modified ,
+ pubDate: post.dateToCmp,
title: post.data.title,
},
}));
diff --git a/src/pages/posts/[...page].astro b/src/pages/posts/[...page].astro
index 5c3c4d2..0c484ec 100644
--- a/src/pages/posts/[...page].astro
+++ b/src/pages/posts/[...page].astro
@@ -7,11 +7,10 @@ import PageLayout from "@/layouts/Base.astro";
import { collectionDateSort } from "@/utils/date";
import type { GetStaticPaths, Page } from "astro";
import { Icon } from "astro-icon/components";
+import { MAX_TAGS, MAX_CATEGORIES, MAX_POSTS_PER_PAGE } from "@/utils/constant";
+import type { PostItem } from "@/types";
export const getStaticPaths = (async ({ paginate }) => {
- const MAX_POSTS_PER_PAGE = 20;
- const MAX_TAGS = 7;
- const MAX_CATEGORIES = 7;
const allPosts = await getAllPosts();
const uniqueTags = getUniqueTags(allPosts).slice(0, MAX_TAGS);
const uniqueCategories = getUniqueCategories(allPosts).slice(0, MAX_CATEGORIES);
@@ -23,7 +22,7 @@ export const getStaticPaths = (async ({ paginate }) => {
}) satisfies GetStaticPaths;
interface Props {
- page: Page>;
+ page: Page;
uniqueTags: string[];
uniqueCategories: string[];
postsCount: number;
@@ -90,7 +89,7 @@ const descYearKeys = Object.keys(groupedByYear).sort((a, b) => +b - +a);
!!uniqueTags.length && (