PR feedback
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
95d3328cda
commit
e1b41e2a37
|
@ -60,15 +60,13 @@ export async function getEventsByTerm(
|
|||
year: string,
|
||||
term: string
|
||||
): Promise<string[]> {
|
||||
let retval: string[] = [];
|
||||
try {
|
||||
retval = (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
||||
return (await fs.readdir(path.join(EVENTS_PATH, year, term)))
|
||||
.filter((name) => name.endsWith(".md"))
|
||||
.map((name) => name.slice(0, -".md".length));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
export async function getUpcomingEvents(): Promise<Event[]> {
|
||||
|
@ -106,10 +104,7 @@ export async function getUpcomingEvents(): Promise<Event[]> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getProps(
|
||||
year: string,
|
||||
term: string
|
||||
): Promise<{ props: Props }> {
|
||||
export async function getProps(year: string, term: string): Promise<Props> {
|
||||
const eventNames = await getEventsByTerm(year, term);
|
||||
|
||||
const events: Event[] = (
|
||||
|
@ -145,6 +140,7 @@ export async function getProps(
|
|||
pastTerms.push(pastTerm);
|
||||
}
|
||||
}
|
||||
pastTerms.reverse();
|
||||
|
||||
const maxYear = eventYears[eventYears.length - 1];
|
||||
const futureTerms: { year: string; term: string }[] = [];
|
||||
|
@ -163,15 +159,13 @@ export async function getProps(
|
|||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
year: year,
|
||||
term: term,
|
||||
pastEvents: pastEvents,
|
||||
futureEvents: futureEvents,
|
||||
isCurrentTerm: term === current.term && year === current.year,
|
||||
pastTerms: pastTerms,
|
||||
futureTerms: futureTerms,
|
||||
},
|
||||
year: year,
|
||||
term: term,
|
||||
pastEvents: pastEvents,
|
||||
futureEvents: futureEvents,
|
||||
isCurrentTerm: term === current.term && year === current.year,
|
||||
pastTerms: pastTerms,
|
||||
futureTerms: futureTerms,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -181,18 +175,18 @@ export function getCurrentTerm(): { year: string; term: string } {
|
|||
const year = date.getUTCFullYear().toString();
|
||||
|
||||
if (
|
||||
new Date(`${year}-01-01`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-04-30`).getTime()
|
||||
new Date(`${year}-01-01 EST`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-04-30 EST`).getTime()
|
||||
) {
|
||||
term = "winter";
|
||||
} else if (
|
||||
new Date(`${year}-05-01`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-08-31`).getTime()
|
||||
new Date(`${year}-05-01 EST`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-08-31 EST`).getTime()
|
||||
) {
|
||||
term = "spring";
|
||||
} else if (
|
||||
new Date(`${year}-09-01`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-12-31`).getTime()
|
||||
new Date(`${year}-09-01 EST`).getTime() <= date.getTime() &&
|
||||
date.getTime() <= new Date(`${year}-12-31 EST`).getTime()
|
||||
) {
|
||||
term = "fall";
|
||||
}
|
||||
|
@ -205,20 +199,20 @@ function getPastTerm(
|
|||
term: string
|
||||
): { year: string; term: string } {
|
||||
const index = TERMS.indexOf(term);
|
||||
|
||||
if (index === -1) {
|
||||
console.error("Not a valid term");
|
||||
return { year: "", term: "" };
|
||||
} else if (index === 0) {
|
||||
return {
|
||||
year: (parseInt(year) - 1).toString(),
|
||||
term: TERMS[TERMS.length - 1],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
year: year,
|
||||
term: TERMS[index - 1],
|
||||
};
|
||||
throw new Error("Not a valid term");
|
||||
}
|
||||
|
||||
return index === 0
|
||||
? {
|
||||
year: (parseInt(year) - 1).toString(),
|
||||
term: TERMS[TERMS.length - 1],
|
||||
}
|
||||
: {
|
||||
year: year,
|
||||
term: TERMS[index - 1],
|
||||
};
|
||||
}
|
||||
|
||||
function getFutureTerm(
|
||||
|
@ -226,18 +220,18 @@ function getFutureTerm(
|
|||
term: string
|
||||
): { year: string; term: string } {
|
||||
const index = TERMS.indexOf(term);
|
||||
|
||||
if (index === -1) {
|
||||
console.error("Not a valid term");
|
||||
return { year: "", term: "" };
|
||||
} else if (index === TERMS.length - 1) {
|
||||
return {
|
||||
year: (parseInt(year) + 1).toString(),
|
||||
term: TERMS[0],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
year: year,
|
||||
term: TERMS[index + 1],
|
||||
};
|
||||
throw new Error("Not a valid term");
|
||||
}
|
||||
|
||||
return index === TERMS.length - 1
|
||||
? {
|
||||
year: (parseInt(year) + 1).toString(),
|
||||
term: TERMS[0],
|
||||
}
|
||||
: {
|
||||
year: year,
|
||||
term: TERMS[index + 1],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -27,72 +27,42 @@ export interface Props {
|
|||
}
|
||||
|
||||
export default function Term(props: Props) {
|
||||
const hasPastTerms = props.pastTerms.length !== 0;
|
||||
const hasFutureTerms = props.futureTerms.length !== 0;
|
||||
let headerTerms = [{ year: props.year, term: props.term }];
|
||||
|
||||
// p, Current, f
|
||||
if (props.pastTerms.length > 0 && props.futureTerms.length > 0) {
|
||||
headerTerms = [
|
||||
...props.pastTerms.slice(-1),
|
||||
...headerTerms,
|
||||
...props.futureTerms.slice(0, 1),
|
||||
];
|
||||
}
|
||||
// p, p, Current
|
||||
else if (props.pastTerms.length > 0) {
|
||||
headerTerms = [...props.pastTerms.slice(-2), ...headerTerms];
|
||||
}
|
||||
// Current, f, f
|
||||
else {
|
||||
headerTerms = [...headerTerms, ...props.futureTerms.slice(0, 2)];
|
||||
}
|
||||
|
||||
headerTerms.reverse();
|
||||
|
||||
const hasPastEvents = props.pastEvents.length !== 0;
|
||||
const hasFutureEvents = props.futureEvents.length !== 0;
|
||||
|
||||
return (
|
||||
<div className={styles.main}>
|
||||
{!hasPastTerms && hasFutureTerms && (
|
||||
<div className={styles.header}>
|
||||
<Link href={`/events/${props.year}/${props.term}`}>
|
||||
<span className={styles.curTerm}>
|
||||
{`${capitalize(props.term)} ${props.year}`}
|
||||
</span>
|
||||
</Link>
|
||||
<Link
|
||||
href={`/events/${props.futureTerms[0].year}/${props.futureTerms[0].term}`}
|
||||
>{`${capitalize(props.futureTerms[0].term)} ${
|
||||
props.futureTerms[0].year
|
||||
}`}</Link>
|
||||
<Link
|
||||
href={`/events/${props.futureTerms[1].year}/${props.futureTerms[1].term}`}
|
||||
>{`${capitalize(props.futureTerms[1].term)} ${
|
||||
props.futureTerms[1].year
|
||||
}`}</Link>
|
||||
<Link href={"/events/archives"}>Archives</Link>
|
||||
</div>
|
||||
)}
|
||||
{hasPastTerms && hasFutureTerms && (
|
||||
<div className={styles.header}>
|
||||
<Link
|
||||
href={`/events/${props.pastTerms[0].year}/${props.pastTerms[0].term}`}
|
||||
>{`${capitalize(props.pastTerms[0].term)} ${
|
||||
props.pastTerms[0].year
|
||||
}`}</Link>
|
||||
<Link href={`/events/${props.year}/${props.term}`}>
|
||||
<span className={styles.curTerm}>
|
||||
{`${capitalize(props.term)} ${props.year}`}
|
||||
</span>
|
||||
</Link>
|
||||
<Link
|
||||
href={`/events/${props.futureTerms[0].year}/${props.futureTerms[0].term}`}
|
||||
>{`${capitalize(props.futureTerms[0].term)} ${
|
||||
props.futureTerms[0].year
|
||||
}`}</Link>
|
||||
<Link href={"/events/archives"}>Archives</Link>
|
||||
</div>
|
||||
)}
|
||||
{hasPastTerms && !hasFutureTerms && (
|
||||
<div className={styles.header}>
|
||||
<Link
|
||||
href={`/events/${props.pastTerms[1].year}/${props.pastTerms[1].term}`}
|
||||
>{`${capitalize(props.pastTerms[1].term)} ${
|
||||
props.pastTerms[1].year
|
||||
} `}</Link>
|
||||
<Link
|
||||
href={`/events/${props.pastTerms[0].year}/${props.pastTerms[0].term}`}
|
||||
>{`${capitalize(props.pastTerms[0].term)} ${
|
||||
props.pastTerms[0].year
|
||||
}`}</Link>
|
||||
<Link href={`/events/${props.year}/${props.term}`}>
|
||||
<span className={styles.curTerm}>
|
||||
{`${capitalize(props.term)} ${props.year}`}
|
||||
</span>
|
||||
</Link>
|
||||
<Link href={"/events/archives"}>Archives</Link>
|
||||
</div>
|
||||
)}
|
||||
<div className={styles.header}>
|
||||
{headerTerms.map((link) => (
|
||||
<HeaderLink
|
||||
{...link}
|
||||
isCurrentTerm={link.year === props.year && link.term === props.term}
|
||||
key={link.year + link.term}
|
||||
/>
|
||||
))}
|
||||
<Link href="/events/archives">Archives</Link>
|
||||
</div>
|
||||
{hasFutureEvents && (
|
||||
<>
|
||||
<h2>Upcoming Events</h2>
|
||||
|
@ -132,6 +102,20 @@ export default function Term(props: Props) {
|
|||
);
|
||||
}
|
||||
|
||||
function HeaderLink(props: {
|
||||
year: string;
|
||||
term: string;
|
||||
isCurrentTerm?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Link href={`/events/${props.year}/${props.term}`}>
|
||||
<span className={props.isCurrentTerm ? styles.curTerm : ""}>
|
||||
{`${capitalize(props.term)} ${props.year}`}
|
||||
</span>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
interface Params extends ParsedUrlQuery {
|
||||
year: string;
|
||||
term: string;
|
||||
|
@ -143,7 +127,7 @@ export const getStaticProps: GetStaticProps<Props, Params> = async (
|
|||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const { year, term } = context.params!;
|
||||
|
||||
return await getProps(year, term);
|
||||
return { props: await getProps(year, term) };
|
||||
};
|
||||
|
||||
export const getStaticPaths: GetStaticPaths<Params> = async () => {
|
||||
|
|
Loading…
Reference in New Issue