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';
|
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));
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<Base>
|
||||||
{pages.map(entry => (
|
{pages.map(entry => (
|
||||||
<div>
|
<div>
|
||||||
{entry.id}
|
<a href={entry.slug.split('/')[1]}>{entry.id}</a>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
</Base>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue