www-new/pages/events/[year]/index.tsx

62 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-19 11:22:25 -04:00
import { ParsedUrlQuery } from "querystring";
import { GetStaticPaths, GetStaticProps } from "next";
2021-08-16 19:51:00 -04:00
import React from "react";
2021-08-17 14:50:32 -04:00
2021-08-19 11:22:25 -04:00
import { Link } from "@/components/Link";
import { getEventYears, getEventTermsByYear } from "@/lib/events";
2021-08-17 14:50:32 -04:00
2021-08-23 22:29:45 -04:00
import styles from "./index.module.css";
2021-08-16 19:51:00 -04:00
2021-08-18 11:42:10 -04:00
interface Props {
year: string;
terms: string[];
}
2021-08-19 11:22:25 -04:00
export default function Year(props: Props) {
2021-08-16 19:51:00 -04:00
return (
<div className={styles.main}>
2021-08-22 14:46:23 -04:00
<h2>
2021-08-16 19:51:00 -04:00
Events Archive:<span className={styles.blue}>{` ${props.year}`}</span>
</h2>
2021-08-22 14:46:23 -04:00
<ul className={styles.list}>
2021-08-16 19:51:00 -04:00
{props.terms.map((term) => (
2021-08-22 14:46:23 -04:00
<li key={`${props.year}-${term}`}>
<Link href={`/events/${props.year}/${term}`}>
{`${term.charAt(0).toUpperCase()}${term.slice(1)}`}
</Link>
</li>
2021-08-16 19:51:00 -04:00
))}
2021-08-22 14:46:23 -04:00
</ul>
2021-08-16 19:51:00 -04:00
</div>
);
2021-08-19 11:22:25 -04:00
}
interface Params extends ParsedUrlQuery {
year: string;
}
export const getStaticProps: GetStaticProps<Props, Params> = async (
context
) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const { year } = context.params!;
return {
props: {
year: year,
terms: await getEventTermsByYear(year),
},
};
2021-08-16 19:51:00 -04:00
};
2021-08-19 11:22:25 -04:00
export const getStaticPaths: GetStaticPaths<Params> = async () => {
const years = await getEventYears();
const paths = years.map((curYear) => ({
params: { year: curYear },
}));
return {
paths: paths,
fallback: false,
};
};