diff --git a/src/components/site/SiteArchives.tsx b/src/components/site/SiteArchives.tsx index 85078764..b00c3c2e 100644 --- a/src/components/site/SiteArchives.tsx +++ b/src/components/site/SiteArchives.tsx @@ -3,11 +3,13 @@ import { useMemo } from "react" import { formatDate } from "~/lib/date" import { EmptyState } from "../ui/EmptyState" import { Notes, Note } from "~/lib/types" +import { UniLink } from "../ui/UniLink" export const SiteArchives: React.FC<{ posts?: Notes title?: string -}> = ({ posts, title }) => { + showTags?: boolean +}> = ({ posts, title, showTags }) => { const groupedByYear = useMemo>(() => { const map = new Map() @@ -23,6 +25,26 @@ export const SiteArchives: React.FC<{ return map }, [posts]) + const tags = useMemo>(() => { + const result = new Map() + + if (posts) { + for (const post of posts.list) { + post.tags?.forEach((tag) => { + if (tag !== "post" && tag !== "page") { + if (result.has(tag)) { + result.set(tag, result.get(tag) + 1) + } else { + result.set(tag, 1) + } + } + }) + } + } + + return result + }, [posts]) + if (!posts) return null return ( @@ -34,30 +56,49 @@ export const SiteArchives: React.FC<{ )} {posts.list.length > 0 && ( -
- {[...groupedByYear.keys()].map((year) => { - const posts = groupedByYear.get(year)! - return ( -
-

{year}

- {posts.map((post) => { - return ( - - {post.title} - - {formatDate(post.date_published, "MMM D")} - - - ) - })} + <> + {showTags && tags.size > 0 && ( +
+

Tags

+
+ {[...tags.keys()].map((tag) => ( + + {tag} + + ({tags.get(tag)}) + + + ))}
- ) - })} -
+
+ )} +
+ {[...groupedByYear.keys()].map((year) => { + const posts = groupedByYear.get(year)! + return ( +
+

+ {year} +

+ {posts.map((post) => { + return ( + + {post.title} + + {formatDate(post.date_published, "MMM D")} + + + ) + })} +
+ ) + })} +
+ )} ) diff --git a/src/pages/_site/[site]/archives.tsx b/src/pages/_site/[site]/archives.tsx index be0c34c8..4a1f7d32 100644 --- a/src/pages/_site/[site]/archives.tsx +++ b/src/pages/_site/[site]/archives.tsx @@ -39,7 +39,7 @@ function SiteArchivesPage({ render: true, }) - return + return } SiteArchivesPage.getLayout = (page: ReactElement) => {