|
|
|
@ -1,50 +1,21 @@ |
|
|
|
|
import { ParsedUrlQuery } from "querystring"; |
|
|
|
|
|
|
|
|
|
import { GetStaticPaths, GetStaticProps } from "next"; |
|
|
|
|
import { MDXRemote } from "next-mdx-remote"; |
|
|
|
|
import React from "react"; |
|
|
|
|
|
|
|
|
|
import { EventCard } from "../../../../components/EventCard"; |
|
|
|
|
import { MiniEventCard } from "../../../../components/MiniEventCard"; |
|
|
|
|
import { EventCard } from "@/components/EventCard"; |
|
|
|
|
import { MiniEventCard } from "@/components/MiniEventCard"; |
|
|
|
|
import { |
|
|
|
|
getEventYears, |
|
|
|
|
getEventTermsByYear, |
|
|
|
|
getEventsByTerm, |
|
|
|
|
getEventBySlug, |
|
|
|
|
Event, |
|
|
|
|
} from "../../../../lib/events"; |
|
|
|
|
} from "@/lib/events"; |
|
|
|
|
|
|
|
|
|
import styles from "./term.module.css"; |
|
|
|
|
|
|
|
|
|
export async function getStaticPaths(): Promise<{ |
|
|
|
|
paths: { |
|
|
|
|
params: { |
|
|
|
|
year: string; |
|
|
|
|
term: string; |
|
|
|
|
}; |
|
|
|
|
}[]; |
|
|
|
|
fallback: boolean; |
|
|
|
|
}> { |
|
|
|
|
const years = await getEventYears(); |
|
|
|
|
const paths = []; |
|
|
|
|
for (const year of years) { |
|
|
|
|
const terms = await getEventTermsByYear(year); |
|
|
|
|
const yearPaths = terms.map((curTerm) => ({ |
|
|
|
|
params: { year: year, term: curTerm }, |
|
|
|
|
})); |
|
|
|
|
paths.push(...yearPaths); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
paths: paths, |
|
|
|
|
fallback: false, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Context { |
|
|
|
|
params: { |
|
|
|
|
year: string; |
|
|
|
|
term: string; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
term: string; |
|
|
|
|
year: string; |
|
|
|
@ -52,41 +23,7 @@ interface Props { |
|
|
|
|
futureEvents: Event[]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function getStaticProps(context: Context): Promise<{ |
|
|
|
|
props: Props; |
|
|
|
|
}> { |
|
|
|
|
const events = ( |
|
|
|
|
await Promise.all( |
|
|
|
|
( |
|
|
|
|
await getEventsByTerm(context.params.year, context.params.term) |
|
|
|
|
).map((file: string) => |
|
|
|
|
getEventBySlug(context.params.year, context.params.term, file) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
).sort( |
|
|
|
|
(a, b) => |
|
|
|
|
new Date(a.metadata.date).getTime() - new Date(b.metadata.date).getTime() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const pastEvents = events.filter( |
|
|
|
|
(event) => new Date(event.metadata.date).getTime() < Date.now() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const futureEvents = events.filter( |
|
|
|
|
(event) => new Date(event.metadata.date).getTime() >= Date.now() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
props: { |
|
|
|
|
term: context.params.term, |
|
|
|
|
year: context.params.year, |
|
|
|
|
pastEvents: pastEvents, |
|
|
|
|
futureEvents: futureEvents, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Term = (props: Props) => { |
|
|
|
|
export default function Term(props: Props) { |
|
|
|
|
const hasPastEvents = props.pastEvents.length !== 0; |
|
|
|
|
const hasFutureEvents = props.futureEvents.length !== 0; |
|
|
|
|
|
|
|
|
@ -140,6 +77,61 @@ const Term = (props: Props) => { |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Params extends ParsedUrlQuery { |
|
|
|
|
year: string; |
|
|
|
|
term: string; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps<Props, Params> = async ( |
|
|
|
|
context |
|
|
|
|
) => { |
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
|
const { year, term } = context.params!; |
|
|
|
|
|
|
|
|
|
const eventNames = await getEventsByTerm(year, term); |
|
|
|
|
|
|
|
|
|
const events: Event[] = ( |
|
|
|
|
await Promise.all( |
|
|
|
|
eventNames.map((file: string) => getEventBySlug(year, term, file)) |
|
|
|
|
) |
|
|
|
|
).sort( |
|
|
|
|
(a, b) => |
|
|
|
|
new Date(a.metadata.date).getTime() - new Date(b.metadata.date).getTime() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const pastEvents = events.filter( |
|
|
|
|
(event) => new Date(event.metadata.date).getTime() < Date.now() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const futureEvents = events.filter( |
|
|
|
|
(event) => new Date(event.metadata.date).getTime() >= Date.now() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
props: { |
|
|
|
|
term: term, |
|
|
|
|
year: year, |
|
|
|
|
pastEvents: pastEvents, |
|
|
|
|
futureEvents: futureEvents, |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default Term; |
|
|
|
|
export const getStaticPaths: GetStaticPaths<Params> = async () => { |
|
|
|
|
const years = await getEventYears(); |
|
|
|
|
const paths = []; |
|
|
|
|
for (const year of years) { |
|
|
|
|
const terms = await getEventTermsByYear(year); |
|
|
|
|
const yearPaths = terms.map((curTerm) => ({ |
|
|
|
|
params: { year: year, term: curTerm }, |
|
|
|
|
})); |
|
|
|
|
paths.push(...yearPaths); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
paths: paths, |
|
|
|
|
fallback: false, |
|
|
|
|
}; |
|
|
|
|
}; |
|
|
|
|