feat: sort authors by the number of documents they have and update rendering of author cards accordingly (#21)

Co-authored-by: Team1280Programming <Team1280Programming@users.noreply.github.com>
This commit is contained in:
Team 1280 Programming Laptop 2024-02-19 13:47:31 -08:00 committed by GitHub
parent 7e853fbfdf
commit 8a10f9a9bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
import { affiliations, authors } from '@/app/db/data' import { affiliations, authors, documents } from '@/app/db/data'
import cardEffects from '@/app/styles/cardEffects.module.css' import cardEffects from '@/app/styles/cardEffects.module.css'
import { Zilla_Slab } from 'next/font/google' import { Zilla_Slab } from 'next/font/google'
import Image from 'next/image' import Image from 'next/image'
@ -53,20 +53,32 @@ const AuthorCard = ({
) )
} }
const getNumberOfDocumentsByAuthor = (authorId: string) => {
// Filter documents by author
const filteredDocuments = Object.entries(documents)
.filter(([_, doc]) => doc.manifest.authors.includes(authorId))
.map(([slug, doc]) => ({ slug, doc }))
return filteredDocuments.length
}
const Page = () => { const Page = () => {
const sortedAuthors = Object.entries(authors).sort((a, b) => {
const numDocsA = getNumberOfDocumentsByAuthor(a[0])
const numDocsB = getNumberOfDocumentsByAuthor(b[0])
return numDocsB - numDocsA
})
return ( return (
<div className='p-6'> <div className='p-6'>
<h1 className={`${zillaSlab.className} text-6xl text-center mb-10`}> <h1 className={`${zillaSlab.className} text-6xl text-center mb-10`}>
Authors Authors
</h1> </h1>
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4'> <div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4'>
{Object.keys(authors).map((authorShortName) => { {sortedAuthors.map((entry) => {
return ( return (
<Fragment key={authorShortName}> <Fragment key={entry[0]}>
<AuthorCard <AuthorCard key={entry[0]} params={{ shortName: entry[0] }} />
key={authorShortName}
params={{ shortName: authorShortName }}
/>
</Fragment> </Fragment>
) )
})} })}