improve code style and readability

pull/396/head
Rebecca-Chou 9 months ago
parent cafdf334fe
commit caf0613118
  1. 23
      lib/team.ts
  2. 4
      pages/about/team.tsx

@ -1,4 +1,4 @@
import { readFile, readdir, access } from "fs/promises";
import { readFile, access } from "fs/promises";
import path from "path";
import matter from "gray-matter";
@ -6,12 +6,13 @@ import { Client } from "ldapts";
import { serialize } from "next-mdx-remote/serialize";
import { getCurrentTerm } from "@/lib/events";
import { capitalize } from "@/utils";
const EXECS_PATH = path.join("content", "team", "execs");
const fileType = ".md";
const FILETYPE = ".md";
const { year, term } = getCurrentTerm();
const execPositions: { [name: string]: string } = {
const execPositions: { [position: string]: string } = {
president: "President",
"vice-president": "Vice President",
secretary: "Assistant Vice President",
@ -19,7 +20,7 @@ const execPositions: { [name: string]: string } = {
sysadmin: "System Administrator",
};
const positionNames: string[] = [
const orderedExecPositions: string[] = [
"president",
"vice-president",
"secretary",
@ -43,7 +44,7 @@ export async function getExecNamePosPairs() {
const client = new Client({ url });
// position: name
const execMembers: { [name: string]: string } = {};
const execMembers: { [position: string]: string } = {};
let formattedExec: [string, string][] = [];
try {
@ -69,7 +70,7 @@ export async function getExecNamePosPairs() {
}
});
formattedExec = positionNames.map((position) => {
formattedExec = orderedExecPositions.map((position) => {
return [
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
position
@ -92,7 +93,7 @@ export async function getExec(name: string, pos: string, convert = true) {
let content, metadata;
try {
const raw = await readFile(path.join(EXECS_PATH, `${name}${fileType}`));
const raw = await readFile(path.join(EXECS_PATH, `${name}${FILETYPE}`));
({ content, data: metadata } = matter(raw));
const image = await getMemberImagePath(metadata.name);
@ -103,13 +104,11 @@ export async function getExec(name: string, pos: string, convert = true) {
};
} catch (err) {
// Capitalize the first letter of the first name and last name
const firstName =
name.split("-")[0][0].toUpperCase() + name.split("-")[0].slice(1);
const lastName =
name.split("-")[1][0].toUpperCase() + name.split("-")[1].slice(1);
const firstName = capitalize(name.split("-")[0]);
const lastName = capitalize(name.split("-")[1]);
const posName = execPositions[pos];
content = "Coming Soon";
content = "Coming Soon!";
metadata = {
name: `${firstName} ${lastName}`,
role: `${posName}`,

@ -211,7 +211,9 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
const execNamePosPairs = await getExecNamePosPairs();
const execs = (await Promise.all(
execNamePosPairs.map((posPairs) => getExec(posPairs[0], posPairs[1]))
execNamePosPairs.map((namePosPair) =>
getExec(namePosPair[0], namePosPair[1])
)
)) as SerializedExec[];
const [

Loading…
Cancel
Save