sort author documents by date

This commit is contained in:
Youwen Wu 2024-02-14 15:03:13 -08:00
parent 313611350c
commit 7478a17822
2 changed files with 18 additions and 14 deletions

View file

@ -8,21 +8,20 @@ interface DocumentWithSlug {
doc: Document
}
export default function findDocumentsByAuthor(
export default function findDocumentsByAuthorSorted(
authorId: string
): DocumentWithSlug[] {
// Initialize an empty array to store the results
const result: DocumentWithSlug[] = []
// Filter documents by author
const filteredDocuments = Object.entries(documents)
.filter(([_, doc]) => doc.manifest.authors.includes(authorId))
.map(([slug, doc]) => ({ slug, doc }))
// Iterate over the documents object entries
for (const [slug, doc] of Object.entries(documents)) {
// Check if the authorId is present in the document's authors array
if (doc.manifest.authors.includes(authorId)) {
// If present, push the document along with its slug to the results array
result.push({ slug, doc })
}
}
// Sort the filtered documents by the latest date in descending order
const sortedDocuments = filteredDocuments.sort((a, b) => {
const latestDateA = a.doc.manifest.dates[a.doc.manifest.dates.length - 1]
const latestDateB = b.doc.manifest.dates[b.doc.manifest.dates.length - 1]
return latestDateB - latestDateA // For descending order
})
// Return the results array
return result
return sortedDocuments
}

View file

@ -532,7 +532,7 @@ export const authors: Readonly<{ [key: string]: Author }> = {
},
affiliation: ['Wage Slave@primos', 'Student@srvhs'],
image: '/img/profiles/cbordalo.jpg',
nationality: ['stateless', 'unknown'],
nationality: ['phl', 'usa'],
},
}
@ -763,6 +763,11 @@ export const nationalities: Readonly<{ [key: string]: Nationality }> = {
demonym: 'Israeli',
flag: 'https://upload.wikimedia.org/wikipedia/commons/5/5c/Israel_flag_300.png?20050629023821',
},
phl: {
name: 'Republic of the Philippines',
demonym: 'Filipino',
flag: 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/99/Flag_of_the_Philippines.svg/2880px-Flag_of_the_Philippines.svg.png',
},
unknown: {
name: 'Undetermined',
demonym: 'Undetermined',