Begin work on aoc list pages
This commit is contained in:
parent
2061c1e8b5
commit
18ec1abed9
|
@ -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 => (
|
||||
<div>
|
||||
{entry.id}
|
||||
</div>
|
||||
))}
|
||||
<Base>
|
||||
{pages.map(entry => (
|
||||
<div>
|
||||
<a href={entry.slug.split('/')[1]}>{entry.id}</a>
|
||||
</div>
|
||||
))}
|
||||
</Base>
|
||||
|
|
|
@ -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})
|
||||
---
|
||||
|
||||
<div>{posts.length}</div>
|
||||
|
||||
|
||||
<Base>
|
||||
{Object.entries(map).map(([year, count]) => (
|
||||
<div><a href={year}>{year} - {count}</a></div>
|
||||
))}
|
||||
</Base>
|
||||
|
|
Loading…
Reference in a new issue