sort author documents by date
This commit is contained in:
parent
313611350c
commit
7478a17822
2 changed files with 18 additions and 14 deletions
|
@ -8,21 +8,20 @@ interface DocumentWithSlug {
|
||||||
doc: Document
|
doc: Document
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function findDocumentsByAuthor(
|
export default function findDocumentsByAuthorSorted(
|
||||||
authorId: string
|
authorId: string
|
||||||
): DocumentWithSlug[] {
|
): DocumentWithSlug[] {
|
||||||
// Initialize an empty array to store the results
|
// Filter documents by author
|
||||||
const result: DocumentWithSlug[] = []
|
const filteredDocuments = Object.entries(documents)
|
||||||
|
.filter(([_, doc]) => doc.manifest.authors.includes(authorId))
|
||||||
|
.map(([slug, doc]) => ({ slug, doc }))
|
||||||
|
|
||||||
// Iterate over the documents object entries
|
// Sort the filtered documents by the latest date in descending order
|
||||||
for (const [slug, doc] of Object.entries(documents)) {
|
const sortedDocuments = filteredDocuments.sort((a, b) => {
|
||||||
// Check if the authorId is present in the document's authors array
|
const latestDateA = a.doc.manifest.dates[a.doc.manifest.dates.length - 1]
|
||||||
if (doc.manifest.authors.includes(authorId)) {
|
const latestDateB = b.doc.manifest.dates[b.doc.manifest.dates.length - 1]
|
||||||
// If present, push the document along with its slug to the results array
|
return latestDateB - latestDateA // For descending order
|
||||||
result.push({ slug, doc })
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the results array
|
return sortedDocuments
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -532,7 +532,7 @@ export const authors: Readonly<{ [key: string]: Author }> = {
|
||||||
},
|
},
|
||||||
affiliation: ['Wage Slave@primos', 'Student@srvhs'],
|
affiliation: ['Wage Slave@primos', 'Student@srvhs'],
|
||||||
image: '/img/profiles/cbordalo.jpg',
|
image: '/img/profiles/cbordalo.jpg',
|
||||||
nationality: ['stateless', 'unknown'],
|
nationality: ['phl', 'usa'],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,6 +763,11 @@ export const nationalities: Readonly<{ [key: string]: Nationality }> = {
|
||||||
demonym: 'Israeli',
|
demonym: 'Israeli',
|
||||||
flag: 'https://upload.wikimedia.org/wikipedia/commons/5/5c/Israel_flag_300.png?20050629023821',
|
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: {
|
unknown: {
|
||||||
name: 'Undetermined',
|
name: 'Undetermined',
|
||||||
demonym: 'Undetermined',
|
demonym: 'Undetermined',
|
||||||
|
|
Loading…
Reference in a new issue