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:
parent
7e853fbfdf
commit
8a10f9a9bf
1 changed files with 19 additions and 7 deletions
|
@ -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>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|
Loading…
Reference in a new issue