Add events archive (#187)
Closes #117 Reviewed-on: #187 Reviewed-by: j285he <j285he@localhost> Co-authored-by: Aditya Thakral <a3thakra@csclub.uwaterloo.ca> Co-committed-by: Aditya Thakral <a3thakra@csclub.uwaterloo.ca>pull/193/head
parent
4fb5b656bf
commit
c31571f745
@ -0,0 +1,44 @@ |
||||
import React from "react"; |
||||
|
||||
import { Link } from "@/components/Link"; |
||||
import { |
||||
ShapesConfig, |
||||
GetShapesConfig, |
||||
defaultGetShapesConfig, |
||||
} from "@/components/ShapesBackground"; |
||||
import { capitalize } from "@/utils"; |
||||
|
||||
import styles from "./ArchivePage.module.css"; |
||||
|
||||
export interface Props { |
||||
type: "news" | "events"; |
||||
items: { |
||||
year: string; |
||||
terms: string[]; |
||||
}[]; |
||||
} |
||||
|
||||
export function ArchivePage({ items, type }: Props) { |
||||
return ( |
||||
<div className={styles.page}> |
||||
<h1>{capitalize(type)} Archive</h1> |
||||
<ul className={styles.list}> |
||||
{items.map(({ year, terms }) => |
||||
terms.map((term) => ( |
||||
<li key={`/${type}/${year}/${term}`}> |
||||
<Link href={`/${type}/${year}/${term}`}> |
||||
{capitalize(term)} {year} |
||||
</Link> |
||||
</li> |
||||
)) |
||||
)} |
||||
</ul> |
||||
</div> |
||||
); |
||||
} |
||||
|
||||
ArchivePage.getShapesConfig = ((width, height) => { |
||||
return window.innerWidth <= 768 |
||||
? ({} as ShapesConfig) |
||||
: defaultGetShapesConfig(width, height); |
||||
}) as GetShapesConfig; |
@ -0,0 +1,18 @@ |
||||
import { GetStaticProps } from "next"; |
||||
|
||||
import { ArchivePage, Props } from "@/components/ArchivePage"; |
||||
import { getEventTermsByYear, getEventYears } from "@/lib/events"; |
||||
|
||||
export default ArchivePage; |
||||
|
||||
export const getStaticProps: GetStaticProps<Props> = async () => { |
||||
const years = (await getEventYears()).reverse(); |
||||
const yearsWithTerms = await Promise.all( |
||||
years.map(async (year) => ({ |
||||
year, |
||||
terms: (await getEventTermsByYear(year)).reverse(), |
||||
})) |
||||
); |
||||
|
||||
return { props: { items: yearsWithTerms, type: "events" } }; |
||||
}; |
Loading…
Reference in new issue