diff --git a/src/app/author/[author]/findDocumentsByAuthor.ts b/src/app/author/[author]/findDocumentsByAuthor.ts index de7454b..5a2d904 100644 --- a/src/app/author/[author]/findDocumentsByAuthor.ts +++ b/src/app/author/[author]/findDocumentsByAuthor.ts @@ -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 } diff --git a/src/app/db/data.ts b/src/app/db/data.ts index 8f5c6c4..a5a1c73 100644 --- a/src/app/db/data.ts +++ b/src/app/db/data.ts @@ -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',