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

69 lines
1.3 KiB
TypeScript

import React from "react";
import { getYears, getTermsByYear } from "../../../lib/events";
import styles from "./year.module.css";
import { Link } from "../../../components/Link";
export async function getStaticPaths(): Promise<{
paths: {
params: {
year: string;
};
}[];
fallback: boolean;
}> {
const years = await getYears();
const paths = years.map((curYear) => ({
params: { year: curYear },
}));
console.log(paths);
return {
paths: paths,
fallback: false,
};
}
interface Context {
params: {
year: string;
};
}
export async function getStaticProps(context: Context): Promise<{
props: {
year: string;
terms: string[];
};
}> {
return {
props: {
year: context.params.year,
terms: await getTermsByYear(context.params.year),
},
};
}
interface Props {
year: string;
terms: string[];
}
const Year = (props: Props) => {
return (
<div className={styles.main}>
<h2 className={styles.heading2}>
Events Archive:<span className={styles.blue}>{` ${props.year}`}</span>
</h2>
<hr />
<div className={styles.links}>
{props.terms.map((term) => (
<Link key={term} href={`./${props.year}/${term}`}>
{`${term.charAt(0).toUpperCase()}${term.slice(1)}`}
</Link>
))}
</div>
</div>
);
};
export default Year;