Begin work on aoc list pages

This commit is contained in:
Maciej Jur 2023-04-08 03:01:13 +02:00
parent 2061c1e8b5
commit 18ec1abed9
2 changed files with 23 additions and 11 deletions

View file

@ -1,18 +1,21 @@
--- ---
import Base from '../../layouts/Base.astro';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
export async function getStaticPaths () { export async function getStaticPaths () {
return (await getCollection('aoc')) return [...new Set((await getCollection('aoc')).map(e => e.slug.slice(0, 4)))]
.map(entry => entry.slug.slice(0, 4))
.map(year => ({params: {year}, props: {year}})) .map(year => ({params: {year}, props: {year}}))
} }
const { year } = Astro.props; 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 => ( <Base>
<div> {pages.map(entry => (
{entry.id} <div>
</div> <a href={entry.slug.split('/')[1]}>{entry.id}</a>
))} </div>
))}
</Base>

View file

@ -1,10 +1,19 @@
--- ---
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import Base from '../../layouts/Base.astro';
const posts = await getCollection('aoc'); 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})
--- ---
<div>{posts.length}</div> <Base>
{Object.entries(map).map(([year, count]) => (
<div><a href={year}>{year} - {count}</a></div>
))}
</Base>