From 8a10f9a9bf7b7ed704b3ba253254aeddc48a222e Mon Sep 17 00:00:00 2001 From: Team 1280 Programming Laptop <59985235+Team1280Programming@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:47:31 -0800 Subject: [PATCH] feat: sort authors by the number of documents they have and update rendering of author cards accordingly (#21) Co-authored-by: Team1280Programming --- src/app/author/page.tsx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/app/author/page.tsx b/src/app/author/page.tsx index 9d11a7b..0144594 100644 --- a/src/app/author/page.tsx +++ b/src/app/author/page.tsx @@ -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 { Zilla_Slab } from 'next/font/google' 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 sortedAuthors = Object.entries(authors).sort((a, b) => { + const numDocsA = getNumberOfDocumentsByAuthor(a[0]) + const numDocsB = getNumberOfDocumentsByAuthor(b[0]) + return numDocsB - numDocsA + }) + return (

Authors

- {Object.keys(authors).map((authorShortName) => { + {sortedAuthors.map((entry) => { return ( - - + + ) })}