From 18ec1abed95e4164e069fad819525d5a116b7eb2 Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Sat, 8 Apr 2023 03:01:13 +0200 Subject: [PATCH] Begin work on aoc list pages --- src/pages/aoc/[year].astro | 19 +++++++++++-------- src/pages/aoc/index.astro | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/pages/aoc/[year].astro b/src/pages/aoc/[year].astro index 12990dc..fc28336 100644 --- a/src/pages/aoc/[year].astro +++ b/src/pages/aoc/[year].astro @@ -1,18 +1,21 @@ --- +import Base from '../../layouts/Base.astro'; import { getCollection } from 'astro:content'; + export async function getStaticPaths () { - return (await getCollection('aoc')) - .map(entry => entry.slug.slice(0, 4)) + return [...new Set((await getCollection('aoc')).map(e => e.slug.slice(0, 4)))] .map(year => ({params: {year}, props: {year}})) } const { year } = Astro.props; -const pages = await getCollection('aoc', (entry) => entry.id.startsWith(Astro.params.year!)); +const pages = await getCollection('aoc', (entry) => entry.id.startsWith(year)); --- -{pages.map(entry => ( -
- {entry.id} -
-))} \ No newline at end of file + + {pages.map(entry => ( +
+ {entry.id} +
+ ))} + diff --git a/src/pages/aoc/index.astro b/src/pages/aoc/index.astro index f76ebe9..969f0e9 100644 --- a/src/pages/aoc/index.astro +++ b/src/pages/aoc/index.astro @@ -1,10 +1,19 @@ --- import { getCollection } from 'astro:content'; +import Base from '../../layouts/Base.astro'; const posts = await getCollection('aoc'); + +const map = posts.reduce((acc, next) => { + const year = next.slug.slice(0, 4); + (year in acc) ? acc[year] += 1 : acc[year] = 1; + return acc; + }, {} as {[key: string]: number}) --- -
{posts.length}
- - + + {Object.entries(map).map(([year, count]) => ( +
{year} - {count}
+ ))} +