-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #59 ISR for people, projects, and single project pages. temp
- Loading branch information
Showing
11 changed files
with
144 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Attachment } from 'airtable'; | ||
|
||
/** | ||
* Extracts the first image URL from Airtable's attachment array. | ||
* | ||
* @param {Attachment[] | undefined} attachmentArr - Array of Airtable Attachments, or undefined. | ||
* @returns {string | null} The first image URL if found, otherwise `null`. | ||
* | ||
* @example | ||
* const imgUrl = getImgUrlFromAttachmentObj(record.fields.profile_photo); | ||
* console.log(imgUrl); // "https://dl.airtable.com/..." | ||
*/ | ||
export function getImgUrlFromAttachmentObj(attachmentArr?: Attachment[]): string | null { | ||
// Ensure the array is not empty and has at least one image attachment | ||
const targetImg = attachmentArr?.[0]; | ||
return targetImg?.type.includes('image') ? targetImg.url : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { getImgUrlFromAttachmentObj } from './image'; | ||
export { sortPeople } from './people'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Sorts an array of people based on status and role. | ||
* People are categorized into: | ||
* - Active members | ||
* - Alumni | ||
* - Special case: "Stella" | ||
* | ||
* Within each category, people are sorted by: | ||
* - Faculty (predefined order) | ||
* - Ph.D. Candidates → Ph.D. Students (sorted alphabetically) | ||
* - Master's students → Undergraduate students (sorted alphabetically) | ||
* | ||
* @param {Person[]} people - The array of people to sort. | ||
* @returns {Person[]} The sorted array of people. | ||
* | ||
* @example | ||
* const sortedPeople = sortPeople(peopleArray); | ||
* console.log(sortedPeople); | ||
*/ | ||
export function sortPeople(people: Person[]): Person[] { | ||
// Predefined faculty sorting order | ||
const facultyOrder = new Map([ | ||
['Haoqi Zhang', 1], | ||
['Eleanor "Nell" O\'Rourke', 2], | ||
['Matt Easterday', 3], | ||
['Liz Gerber', 4], | ||
]); | ||
|
||
// Predefined Ph.D. role order | ||
const phdOrder = new Map([ | ||
['Ph.D. Candidate', 1], | ||
['Ph.D. Student', 2], | ||
]); | ||
|
||
// Categorize people | ||
const categories = { | ||
active: [] as Person[], | ||
alumni: [] as Person[], | ||
stella: [] as Person[], | ||
}; | ||
|
||
people.forEach((person) => { | ||
if (person.name === 'Stella') { | ||
categories.stella.push(person); | ||
} | ||
else if (person.status === 'Active') { | ||
categories.active.push(person); | ||
} | ||
else if (person.status === 'Alumni') { | ||
categories.alumni.push(person); | ||
} | ||
}); | ||
|
||
// Sorting function by role | ||
const sortByRole = (people: Person[]): Person[] => { | ||
// Sort faculty | ||
const faculty = people.filter(p => p.role === 'Faculty').sort( | ||
(a, b) => (facultyOrder.get(a.name) ?? Infinity) - (facultyOrder.get(b.name) ?? Infinity), | ||
); | ||
|
||
// Sort Ph.D. candidates and students | ||
const phd = people.filter(p => phdOrder.has(p.role)).sort( | ||
(a, b) => (phdOrder.get(a.role) ?? Infinity) - (phdOrder.get(b.role) ?? Infinity) | ||
|| a.name.localeCompare(b.name), | ||
); | ||
|
||
// Sort Master's and Undergraduate students | ||
const masters = people.filter(p => p.role === 'Masters Student Researcher') | ||
.sort((a, b) => a.name.localeCompare(b.name)); | ||
|
||
const ugrads = people.filter(p => p.role === 'Undergraduate Student Researcher') | ||
.sort((a, b) => a.name.localeCompare(b.name)); | ||
|
||
return [...faculty, ...phd, ...masters, ...ugrads]; | ||
}; | ||
|
||
return [...sortByRole(categories.active), ...categories.stella, ...sortByRole(categories.alumni)]; | ||
} |