mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-05-18 16:20: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
4cb2c8a3dd
@ -6,6 +6,7 @@ import {getAllArticles} from '@/lib/getAllArticles'
|
|||||||
import {metadata as _metadata} from '@/lib/generateMetadata'
|
import {metadata as _metadata} from '@/lib/generateMetadata'
|
||||||
import type {Article} from '@/types'
|
import type {Article} from '@/types'
|
||||||
import {format} from 'date-fns'
|
import {format} from 'date-fns'
|
||||||
|
import {Section} from '@/components/ui/Section'
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
title: 'Writing',
|
title: 'Writing',
|
||||||
@ -33,14 +34,34 @@ export let metadata: {
|
|||||||
|
|
||||||
metadata = _metadata({...meta, heading: meta.heading})
|
metadata = _metadata({...meta, heading: meta.heading})
|
||||||
|
|
||||||
function Article({article}: { article: Article }) {
|
export default async function Writing() {
|
||||||
|
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 (
|
return (
|
||||||
<article>
|
<SimpleLayout
|
||||||
<Card variant="inline">
|
heading={meta.heading}
|
||||||
<Card.Title href={`/writing/${article.slug}`}>
|
description={meta.description}
|
||||||
{article.title}
|
gradient="bg-gradient-to-r from-pink-500 to-violet-500"
|
||||||
</Card.Title>
|
>
|
||||||
<p className="flex order-first space-x-1 z-10 mb-3 md:mb-0 md:ml-4 md:order-last flex-shrink-0">
|
<div className="space-y-20">
|
||||||
|
{Object.entries(groupedArticles)
|
||||||
|
.sort(([a], [b]) => parseInt(b) - parseInt(a))
|
||||||
|
.map(([year, articles]) => (
|
||||||
|
<Section title={year} key={year}>
|
||||||
|
<ul role="list" className="space-y-16">
|
||||||
|
{articles.map((article) => (
|
||||||
|
<Card key={article.slug} as="li">
|
||||||
|
<Card.Title href={`/writing/${article.slug}`}>{article.title}</Card.Title>
|
||||||
|
<p className="flex order-first space-x-1 z-10 mb-3">
|
||||||
<Card.Eyebrow as="time" dateTime={article.date} decorate={false}>
|
<Card.Eyebrow as="time" dateTime={article.date} decorate={false}>
|
||||||
{format(article.date, 'd MMMM yyyy')}
|
{format(article.date, 'd MMMM yyyy')}
|
||||||
</Card.Eyebrow>
|
</Card.Eyebrow>
|
||||||
@ -52,25 +73,12 @@ function Article({article}: { article: Article }) {
|
|||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
</Card>
|
</Card>
|
||||||
</article>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async function Writing() {
|
|
||||||
const articles = (await getAllArticles()).map(({component, ...meta}) => meta)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SimpleLayout
|
|
||||||
heading={meta.heading}
|
|
||||||
description={meta.description}
|
|
||||||
gradient="bg-gradient-to-r from-pink-500 to-violet-500"
|
|
||||||
>
|
|
||||||
<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">
|
|
||||||
{articles.map((article) => (
|
|
||||||
<Article key={article.slug} article={article}/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</ul>
|
||||||
|
</Section>
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</SimpleLayout>
|
</SimpleLayout>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user