eliminate position name to keep in sync

ldap-exec-test
Rebecca-Chou 9 months ago
parent 51bb491277
commit 4c087b4af4
  1. 0
      content/team/execs/codey.md
  2. 0
      content/team/execs/dina-orucevic.md
  3. 0
      content/team/execs/eden-chan.md
  4. 0
      content/team/execs/eric-huang.md
  5. 0
      content/team/execs/juthika-hoque.md
  6. 0
      content/team/execs/raymond-li.md
  7. 46
      lib/team.ts
  8. 6
      pages/about/team.tsx

@ -33,11 +33,9 @@ export interface Metadata {
image: string;
}
export async function getExecNames() {
export async function getExecNamePosPairs() {
if (process.env.USE_LDAP?.toLowerCase() !== "true") {
return (await readdir(EXECS_PATH))
.filter((name) => name.endsWith(fileType))
.map((name) => name.slice(0, -1 * fileType.length));
return [["codey", "mascot"]];
}
const url = "ldap://ldap1.csclub.uwaterloo.ca";
@ -46,7 +44,7 @@ export async function getExecNames() {
// position: name
const execMembers: { [name: string]: string } = {};
let formattedExec: string[] = [];
let formattedExec: [string, string][] = [];
try {
await client.bind("", "");
@ -62,7 +60,7 @@ export async function getExecNames() {
searchEntries.forEach((item) => {
if (typeof item.position === "string" && item.position in execPositions) {
execMembers[item.position] = item.cn as string;
} else if (typeof item.position === "object") {
} else if (item.position instanceof Array) {
item.position.forEach((p) => {
if ((p as string) in execPositions) {
execMembers[p as string] = item.cn as string;
@ -71,14 +69,18 @@ export async function getExecNames() {
}
});
formattedExec = positionNames.map(
(position, i) =>
`0${i + 1}-${execMembers[position]
.split(" ")[0]
.toLowerCase()}-${execMembers[position].split(" ")[1].toLowerCase()}`
);
formattedExec = positionNames.map((position) => {
return [
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
position
]
.split(" ")[1]
.toLowerCase()}`,
position,
];
});
formattedExec = [...formattedExec, "06-codey"];
formattedExec = [...formattedExec, ["codey", "mascot"]];
} finally {
await client.unbind();
}
@ -86,11 +88,16 @@ export async function getExecNames() {
return formattedExec;
}
export async function getExec(fileName: string, convert = true) {
export async function getExec(
execNamePosPair: [string, string],
convert = true
) {
let content, metadata;
try {
const raw = await readFile(path.join(EXECS_PATH, `${fileName}${fileType}`));
const raw = await readFile(
path.join(EXECS_PATH, `${execNamePosPair[0]}${fileType}`)
);
({ content, data: metadata } = matter(raw));
const image =
@ -103,12 +110,13 @@ export async function getExec(fileName: string, convert = true) {
};
} catch (err) {
const firstName =
fileName.split("-")[1][0].toUpperCase() + fileName.split("-")[1].slice(1);
execNamePosPair[0].split("-")[0][0].toUpperCase() +
execNamePosPair[0].split("-")[0].slice(1);
const lastName =
fileName.split("-")[2][0].toUpperCase() + fileName.split("-")[2].slice(1);
execNamePosPair[0].split("-")[1][0].toUpperCase() +
execNamePosPair[0].split("-")[1].slice(1);
const posOrder = fileName.split("-")[0][1];
const posName = execPositions[positionNames[Number(posOrder) - 1]];
const posName = execPositions[execNamePosPair[1]];
({ content, metadata } = {
content: "Coming soon!",
metadata: {

@ -11,7 +11,7 @@ import { TeamMemberCard } from "@/components/TeamMemberCard";
import { Title } from "@/components/Title";
import {
getExec,
getExecNames,
getExecNamePosPairs,
Metadata,
getMemberImagePath,
} from "@/lib/team";
@ -140,10 +140,10 @@ async function getTeamWithImages(team: TeamMember[]) {
}
export const getStaticProps: GetStaticProps<Props> = async () => {
const execNames = await getExecNames();
const execNamePosPairs = await getExecNamePosPairs();
const execs = (await Promise.all(
execNames.map((name) => getExec(name))
execNamePosPairs.map((namePosPair) => getExec(namePosPair))
)) as SerializedExec[];
const [programme, website, systems, terminal] = await Promise.all([

Loading…
Cancel
Save