Compare commits
41 Commits
main
...
ldap-exec-
Author | SHA1 | Date |
---|---|---|
Rebecca-Chou | 5adebddec6 | |
Rebecca-Chou | cafdf334fe | |
Rebecca-Chou | 00caa70143 | |
Rebecca-Chou | ccd075fa84 | |
Rebecca-Chou | 67afba862a | |
Rebecca-Chou | 4c087b4af4 | |
Rebecca-Chou | 51bb491277 | |
Rebecca-Chou | 2d9176256d | |
Beihao Zhou | 83b68a3ce3 | |
Rebecca-Chou | 856f849526 | |
Rebecca-Chou | 0c0515a3c6 | |
Rebecca-Chou | 3dbc1efe39 | |
Rebecca-Chou | f09580151f | |
Rebecca-Chou | bb743f4ca6 | |
Rebecca-Chou | ca1a9f3185 | |
Rebecca-Chou | 3506b6d00c | |
Rebecca-Chou | 615a8ddbf9 | |
Rebecca-Chou | 6dc69fbe14 | |
Rebecca-Chou | 9a1ecf82bd | |
Rebecca-Chou | f96d776259 | |
Rebecca-Chou | fe3358d9ae | |
Rebecca-Chou | 340dfa67b5 | |
Rebecca-Chou | 57f67bc8d1 | |
Rebecca-Chou | ae66794a54 | |
Rebecca-Chou | be43b75694 | |
Beihao Zhou | 2aeaeaccde | |
Beihao Zhou | c729bf40ee | |
Rebecca-Chou | 8b8432cf76 | |
Rebecca-Chou | 3a7ec04f4e | |
Rebecca-Chou | ae0b81c4cc | |
Rebecca-Chou | c7947d9054 | |
Rebecca-Chou | 6ad38d1971 | |
Rebecca-Chou | 608f6342da | |
Rebecca-Chou | fc3d3e11d3 | |
Rebecca-Chou | 0f15953979 | |
Beihao Zhou | cb17e15b22 | |
Rebecca-Chou | 79c5005652 | |
Rebecca-Chou | 8f144983ef | |
Rebecca-Chou | fbcdec33eb | |
Rebecca-Chou | 6e8f7bba94 | |
Rebecca-Chou | b06189f5f3 |
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
name: Dina Orucevic
|
||||
role: Assistant Vice President
|
||||
---
|
||||
|
||||
Hi everyone, I’m Dina, a rising 1B student in Systems Design Engineering! I’m so glad I get the chance to lead a group of interested students to make the CS community even more inclusive, diverse, and engaging! In my free time I love snapping film photos, going to dog parks (even though I don’t own a dog) and reading a good novel.
|
120
lib/team.ts
120
lib/team.ts
|
@ -2,10 +2,30 @@ import { readFile, readdir, access } from "fs/promises";
|
|||
import path from "path";
|
||||
|
||||
import matter from "gray-matter";
|
||||
import { Client } from "ldapts";
|
||||
import { serialize } from "next-mdx-remote/serialize";
|
||||
|
||||
import { getCurrentTerm } from "@/lib/events";
|
||||
|
||||
const EXECS_PATH = path.join("content", "team", "execs");
|
||||
const fileType = ".md";
|
||||
const { year, term } = getCurrentTerm();
|
||||
|
||||
const execPositions: { [name: string]: string } = {
|
||||
president: "President",
|
||||
"vice-president": "Vice President",
|
||||
secretary: "Assistant Vice President",
|
||||
treasurer: "Treasurer",
|
||||
sysadmin: "System Administrator",
|
||||
};
|
||||
|
||||
const positionNames: string[] = [
|
||||
"president",
|
||||
"vice-president",
|
||||
"secretary",
|
||||
"treasurer",
|
||||
"sysadmin",
|
||||
];
|
||||
|
||||
export interface Metadata {
|
||||
name: string;
|
||||
|
@ -13,23 +33,95 @@ export interface Metadata {
|
|||
image: string;
|
||||
}
|
||||
|
||||
export async function getExecNames() {
|
||||
return (await readdir(EXECS_PATH))
|
||||
.filter((name) => name.endsWith(fileType))
|
||||
.map((name) => name.slice(0, -1 * fileType.length));
|
||||
export async function getExecNamePosPairs() {
|
||||
if (process.env.USE_LDAP?.toLowerCase() !== "true") {
|
||||
return [["codey", "mascot"]];
|
||||
}
|
||||
|
||||
const url = "ldap://ldap1.csclub.uwaterloo.ca";
|
||||
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
|
||||
const client = new Client({ url });
|
||||
|
||||
// position: name
|
||||
const execMembers: { [name: string]: string } = {};
|
||||
let formattedExec: [string, string][] = [];
|
||||
|
||||
try {
|
||||
await client.bind("", "");
|
||||
const { searchEntries } = await client.search(searchDN, {
|
||||
scope: "sub",
|
||||
filter: `(&(objectClass=member)(term=${(term as string).slice(
|
||||
0,
|
||||
1
|
||||
)}${year}))`,
|
||||
});
|
||||
|
||||
// item.position might be an array if the member has more than one position
|
||||
searchEntries.forEach((item) => {
|
||||
if (typeof item.position === "string" && item.position in execPositions) {
|
||||
execMembers[item.position] = item.cn as string;
|
||||
} else if (item.position instanceof Array) {
|
||||
item.position.forEach((p) => {
|
||||
if ((p as string) in execPositions) {
|
||||
execMembers[p as string] = item.cn as string;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
formattedExec = positionNames.map((position) => {
|
||||
return [
|
||||
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
|
||||
position
|
||||
]
|
||||
.split(" ")[1]
|
||||
.toLowerCase()}`,
|
||||
position,
|
||||
];
|
||||
});
|
||||
|
||||
formattedExec = [...formattedExec, ["codey", "mascot"]];
|
||||
} finally {
|
||||
await client.unbind();
|
||||
}
|
||||
|
||||
return formattedExec;
|
||||
}
|
||||
|
||||
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));
|
||||
export async function getExec(name: string, pos: string, convert = true) {
|
||||
let content, metadata;
|
||||
|
||||
return {
|
||||
content: convert ? await serialize(content) : content,
|
||||
metadata: { ...metadata, image } as Metadata,
|
||||
};
|
||||
try {
|
||||
const raw = await readFile(path.join(EXECS_PATH, `${name}${fileType}`));
|
||||
({ content, data: metadata } = matter(raw));
|
||||
|
||||
const image = await getMemberImagePath(metadata.name);
|
||||
|
||||
return {
|
||||
content: convert ? await serialize(content) : content,
|
||||
metadata: { ...metadata, image } as Metadata,
|
||||
};
|
||||
} 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 posName = execPositions[pos];
|
||||
content = "Coming Soon";
|
||||
metadata = {
|
||||
name: `${firstName} ${lastName}`,
|
||||
role: `${posName}`,
|
||||
};
|
||||
|
||||
const image = await getMemberImagePath(metadata.name);
|
||||
|
||||
return {
|
||||
content: convert ? await serialize(content) : content,
|
||||
metadata: { ...metadata, image } as Metadata,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function getImage(imgPath: string) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import { TeamMemberCard } from "@/components/TeamMemberCard";
|
|||
import { Title } from "@/components/Title";
|
||||
import {
|
||||
getExec,
|
||||
getExecNames,
|
||||
getExecNamePosPairs,
|
||||
Metadata,
|
||||
getMemberImagePath,
|
||||
} from "@/lib/team";
|
||||
|
@ -208,10 +208,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((posPairs) => getExec(posPairs[0], posPairs[1]))
|
||||
)) as SerializedExec[];
|
||||
|
||||
const [
|
||||
|
|
Loading…
Reference in New Issue