diff --git a/src/components/Header.astro b/src/components/Header.astro
index 43a4a7168..e0b1144fb 100644
--- a/src/components/Header.astro
+++ b/src/components/Header.astro
@@ -4,7 +4,7 @@ import Hr from "./Hr.astro";
import LinkButton from "./LinkButton.astro";
export interface Props {
- activeNav?: "posts" | "tags" | "about" | "search";
+ activeNav?: "posts" | "archives" | "tags" | "about" | "search";
}
const { activeNav } = Astro.props;
@@ -70,6 +70,41 @@ const { activeNav } = Astro.props;
About
+ {
+ SITE.showArchives && (
+
+
+
+
+ Archives
+
+
+
+ )
+ }
!data.draft);
+
+const MonthMap: Record = {
+ "1": "January",
+ "2": "February",
+ "3": "March",
+ "4": "April",
+ "5": "May",
+ "6": "June",
+ "7": "July",
+ "8": "August",
+ "9": "September",
+ "10": "October",
+ "11": "November",
+ "12": "December",
+};
+---
+
+
+
+
+ {
+ Object.entries(
+ getPostsByGroupCondition(posts, post =>
+ post.data.pubDatetime.getFullYear()
+ )
+ )
+ .sort(([yearA], [yearB]) => Number(yearB) - Number(yearA))
+ .map(([year, yearGroup]) => (
+
+
{year}
+
{yearGroup.length}
+ {Object.entries(
+ getPostsByGroupCondition(
+ yearGroup,
+ post => post.data.pubDatetime.getMonth() + 1
+ )
+ )
+ .sort(([monthA], [monthB]) => Number(monthB) - Number(monthA))
+ .map(([month, monthGroup]) => (
+
+
+ {MonthMap[month]}
+ {monthGroup.length}
+
+
+ {monthGroup.map(({ data, slug }) => (
+
+ ))}
+
+
+ ))}
+
+ ))
+ }
+
+
+
+
diff --git a/src/types.ts b/src/types.ts
index a5fbb418f..f61effa7f 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -11,6 +11,7 @@ export type Site = {
postPerIndex: number;
postPerPage: number;
scheduledPostMargin: number;
+ showArchives?: boolean;
editPost?: {
url?: URL["href"];
text?: string;
diff --git a/src/utils/getPostsByGroupCondition.ts b/src/utils/getPostsByGroupCondition.ts
new file mode 100644
index 000000000..92e89f589
--- /dev/null
+++ b/src/utils/getPostsByGroupCondition.ts
@@ -0,0 +1,25 @@
+import type { CollectionEntry } from "astro:content";
+
+type GroupKey = string | number | symbol;
+
+interface GroupFunction {
+ (item: T, index?: number): GroupKey;
+}
+
+const getPostsByGroupCondition = (
+ posts: CollectionEntry<"blog">[],
+ groupFunction: GroupFunction>
+) => {
+ const result: Record[]> = {};
+ for (let i = 0; i < posts.length; i++) {
+ const item = posts[i];
+ const groupKey = groupFunction(item, i);
+ if (!result[groupKey]) {
+ result[groupKey] = [];
+ }
+ result[groupKey].push(item);
+ }
+ return result;
+};
+
+export default getPostsByGroupCondition;
diff --git a/tailwind.config.cjs b/tailwind.config.cjs
index 8cad411e4..4a5969282 100644
--- a/tailwind.config.cjs
+++ b/tailwind.config.cjs
@@ -54,6 +54,11 @@ module.exports = {
},
transparent: "transparent",
},
+ stroke: {
+ skin: {
+ accent: withOpacity("--color-accent")
+ }
+ },
fontFamily: {
mono: ["IBM Plex Mono", "monospace"],
},