add placeholder

pull/403/head
Rebecca-Chou 10 months ago
parent 8f144983ef
commit 79c5005652
  1. 71
      lib/team.ts
  2. 3
      pages/about/team.tsx

@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { readFile, readdir, access } from "fs/promises";
import path from "path";
@ -24,16 +23,19 @@ export interface Metadata {
}
export async function getExecNames() {
// 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));
// }
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));
}
const url = "ldap://ldap1.csclub.uwaterloo.ca";
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
const client = new Client({ url });
let execMembers: execMembers[] = [];
let formattedExec: string[];
try {
await client.bind("", "");
const { searchEntries } = await client.search(searchDN, {
@ -44,8 +46,6 @@ export async function getExecNames() {
)}${year})(exec=True))`,
});
let execMembers: execMembers[] = [];
execMembers = searchEntries
.map((item) => {
return {
@ -57,7 +57,7 @@ export async function getExecNames() {
item1.order.localeCompare(item2.order)
);
const formattedExec: string[] = execMembers.map(
formattedExec = execMembers.map(
(member) =>
`0${member.order}-
${member.name.split(" ")[1].toLowerCase()}-
@ -71,16 +71,51 @@ export async function getExecNames() {
}
export async function getExec(fileName: string, convert = true) {
const raw = await readFile(path.join(EXECS_PATH, `${fileName}${fileType}`));
const { content, data: metadata } = matter(raw);
const image =
(metadata.image as string | undefined) ??
(await getMemberImagePath(metadata.name));
return {
content: convert ? await serialize(content) : content,
metadata: { ...metadata, image } as Metadata,
const posDict: { [name: string]: string } = {
"01": "President",
"02": "Vice President",
"03": "Assistant Vice President",
"04": "Treasurer",
"05": "Systems Administrator",
};
const lastName =
fileName.split("-")[1][0].toUpperCase() + fileName.split("-")[1].slice(1);
const firstName =
fileName.split("-")[2][0].toUpperCase() + fileName.split("-")[2].slice(1);
const posOrder = fileName.split("-")[0];
const pos = posDict[posOrder];
let content, metadata;
try {
const raw = await readFile(path.join(EXECS_PATH, `${fileName}${fileType}`));
({ content, data: metadata } = matter(raw));
const image =
(metadata.image as string | undefined) ??
(await getMemberImagePath(metadata.name));
return {
content: convert ? await serialize(content) : content,
metadata: { ...metadata, image } as Metadata,
};
} catch (err) {
({ content, metadata } = {
content: "Coming soon!",
metadata: {
name: `${lastName} ${firstName}`,
role: `${pos}`,
},
});
const image = await getMemberImagePath(metadata.name);
return {
content: convert ? await serialize(content) : content,
metadata: { ...metadata, image } as Metadata,
};
}
}
async function getImage(imgPath: string) {

@ -141,10 +141,11 @@ async function getTeamWithImages(team: TeamMember[]) {
export const getStaticProps: GetStaticProps<Props> = async () => {
const execNames = await getExecNames();
console.log(execNames);
const execs = (await Promise.all(
execNames.map((name) => getExec(name))
)) as SerializedExec[];
const [programme, website, systems, terminal] = await Promise.all([
getTeamWithImages(programmeData),
getTeamWithImages(webData),

Loading…
Cancel
Save