import { getNewsTermsByYear, getNewsYears } from "lib/news";
import { GetStaticProps } from "next";
import React from "react";
import { Link } from "@/components/Link";
import styles from "./archive.module.css";
interface Props {
items: {
year: string;
terms: string[];
}[];
}
export default function NewsArchive({ items }: Props) {
return (
News Archive
{items.map(({ year, terms }) =>
terms.map((term) => (
-
{capitalize(term)} {year}
))
)}
);
}
export const getStaticProps: GetStaticProps = async () => {
const years = (await getNewsYears()).reverse();
const yearsWithTerms = await Promise.all(
years.map(async (year) => ({
year,
terms: (await getNewsTermsByYear(year)).reverse(),
}))
);
return { props: { items: yearsWithTerms } };
};
function capitalize(str: string) {
return str.slice(0, 1).toUpperCase() + str.slice(1);
}