diff --git a/app/writing/page.tsx b/app/writing/page.tsx index 47b8d3e..3c91262 100644 --- a/app/writing/page.tsx +++ b/app/writing/page.tsx @@ -6,6 +6,7 @@ import {getAllArticles} from '@/lib/getAllArticles' import {metadata as _metadata} from '@/lib/generateMetadata' import type {Article} from '@/types' import {format} from 'date-fns' +import {Section} from '@/components/ui/Section' const meta = { title: 'Writing', @@ -33,31 +34,17 @@ export let metadata: { metadata = _metadata({...meta, heading: meta.heading}) -function Article({article}: { article: Article }) { - return ( -
- - - {article.title} - -

- - {format(article.date, 'd MMMM yyyy')} - - -

-
-
- ) -} - export default async function Writing() { - const articles = (await getAllArticles()).map(({component, ...meta}) => meta) + const groupedArticles = (await getAllArticles(true)) + .map(({component, ...meta}) => meta) + .reduce<{ [year: string]: Article[] }>((acc, article) => { + const year = new Date(article.date).getFullYear() + if (!acc[year]) { + acc[year] = [] + } + acc[year].push(article) + return acc + }, {}) return ( -
-
- {articles.map((article) => ( -
- ))} -
+
+ {Object.entries(groupedArticles) + .sort(([a], [b]) => parseInt(b) - parseInt(a)) + .map(([year, articles]) => ( +
+
    + {articles.map((article) => ( + + {article.title} +

    + + {format(article.date, 'd MMMM yyyy')} + + +

    +
    + ))} +
+
+ ) + ) + }
)