improve code style and readability
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
cafdf334fe
commit
caf0613118
23
lib/team.ts
23
lib/team.ts
|
@ -1,4 +1,4 @@
|
||||||
import { readFile, readdir, access } from "fs/promises";
|
import { readFile, access } from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import matter from "gray-matter";
|
import matter from "gray-matter";
|
||||||
|
@ -6,12 +6,13 @@ import { Client } from "ldapts";
|
||||||
import { serialize } from "next-mdx-remote/serialize";
|
import { serialize } from "next-mdx-remote/serialize";
|
||||||
|
|
||||||
import { getCurrentTerm } from "@/lib/events";
|
import { getCurrentTerm } from "@/lib/events";
|
||||||
|
import { capitalize } from "@/utils";
|
||||||
|
|
||||||
const EXECS_PATH = path.join("content", "team", "execs");
|
const EXECS_PATH = path.join("content", "team", "execs");
|
||||||
const fileType = ".md";
|
const FILETYPE = ".md";
|
||||||
const { year, term } = getCurrentTerm();
|
const { year, term } = getCurrentTerm();
|
||||||
|
|
||||||
const execPositions: { [name: string]: string } = {
|
const execPositions: { [position: string]: string } = {
|
||||||
president: "President",
|
president: "President",
|
||||||
"vice-president": "Vice President",
|
"vice-president": "Vice President",
|
||||||
secretary: "Assistant Vice President",
|
secretary: "Assistant Vice President",
|
||||||
|
@ -19,7 +20,7 @@ const execPositions: { [name: string]: string } = {
|
||||||
sysadmin: "System Administrator",
|
sysadmin: "System Administrator",
|
||||||
};
|
};
|
||||||
|
|
||||||
const positionNames: string[] = [
|
const orderedExecPositions: string[] = [
|
||||||
"president",
|
"president",
|
||||||
"vice-president",
|
"vice-president",
|
||||||
"secretary",
|
"secretary",
|
||||||
|
@ -43,7 +44,7 @@ export async function getExecNamePosPairs() {
|
||||||
const client = new Client({ url });
|
const client = new Client({ url });
|
||||||
|
|
||||||
// position: name
|
// position: name
|
||||||
const execMembers: { [name: string]: string } = {};
|
const execMembers: { [position: string]: string } = {};
|
||||||
let formattedExec: [string, string][] = [];
|
let formattedExec: [string, string][] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -69,7 +70,7 @@ export async function getExecNamePosPairs() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
formattedExec = positionNames.map((position) => {
|
formattedExec = orderedExecPositions.map((position) => {
|
||||||
return [
|
return [
|
||||||
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
|
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
|
||||||
position
|
position
|
||||||
|
@ -92,7 +93,7 @@ export async function getExec(name: string, pos: string, convert = true) {
|
||||||
let content, metadata;
|
let content, metadata;
|
||||||
|
|
||||||
try {
|
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));
|
({ content, data: metadata } = matter(raw));
|
||||||
|
|
||||||
const image = await getMemberImagePath(metadata.name);
|
const image = await getMemberImagePath(metadata.name);
|
||||||
|
@ -103,13 +104,11 @@ export async function getExec(name: string, pos: string, convert = true) {
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Capitalize the first letter of the first name and last name
|
// Capitalize the first letter of the first name and last name
|
||||||
const firstName =
|
const firstName = capitalize(name.split("-")[0]);
|
||||||
name.split("-")[0][0].toUpperCase() + name.split("-")[0].slice(1);
|
const lastName = capitalize(name.split("-")[1]);
|
||||||
const lastName =
|
|
||||||
name.split("-")[1][0].toUpperCase() + name.split("-")[1].slice(1);
|
|
||||||
|
|
||||||
const posName = execPositions[pos];
|
const posName = execPositions[pos];
|
||||||
content = "Coming Soon";
|
content = "Coming Soon!";
|
||||||
metadata = {
|
metadata = {
|
||||||
name: `${firstName} ${lastName}`,
|
name: `${firstName} ${lastName}`,
|
||||||
role: `${posName}`,
|
role: `${posName}`,
|
||||||
|
|
|
@ -211,7 +211,9 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
|
||||||
const execNamePosPairs = await getExecNamePosPairs();
|
const execNamePosPairs = await getExecNamePosPairs();
|
||||||
|
|
||||||
const execs = (await Promise.all(
|
const execs = (await Promise.all(
|
||||||
execNamePosPairs.map((posPairs) => getExec(posPairs[0], posPairs[1]))
|
execNamePosPairs.map((namePosPair) =>
|
||||||
|
getExec(namePosPair[0], namePosPair[1])
|
||||||
|
)
|
||||||
)) as SerializedExec[];
|
)) as SerializedExec[];
|
||||||
|
|
||||||
const [
|
const [
|
||||||
|
|
Loading…
Reference in New Issue