mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-05-18 13:10:20 +00:00
Group articles by year
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m13s
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m13s
This commit is contained in:
parent
816e643f55
commit
6e4a28f955
@ -57,7 +57,16 @@ function Article({article}: { article: Article }) {
|
||||
}
|
||||
|
||||
export default async function Writing() {
|
||||
const articles = (await getAllArticles()).map(({component, ...meta}) => meta)
|
||||
const articles = (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 (
|
||||
<SimpleLayout
|
||||
@ -67,9 +76,16 @@ export default async function Writing() {
|
||||
>
|
||||
<div className="mx-auto grid max-w-xl grid-cols-1 gap-y-20 lg:max-w-none">
|
||||
<div className="max-w-3xl space-y-16 mt-6">
|
||||
{Object.entries(articles)
|
||||
.sort(([a], [b]) => parseInt(b) - parseInt(a))
|
||||
.map(([year, articles]) => (
|
||||
<React.Fragment key={year}>
|
||||
<h2 className="text-base font-semibold tracking-tight text-zinc-800 dark:text-zinc-100">{year}</h2>
|
||||
{articles.map((article) => (
|
||||
<Article key={article.slug} article={article}/>
|
||||
))}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</SimpleLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user