diff --git a/src/app/topic/page.tsx b/src/app/topic/page.tsx new file mode 100644 index 0000000..4b7dcc7 --- /dev/null +++ b/src/app/topic/page.tsx @@ -0,0 +1,68 @@ +import { documents, topics } from '@/app/db/data' +import cardEffects from '@/app/styles/cardEffects.module.css' +import string2hex from '@/app/utils/string2hex' +import { Zilla_Slab } from 'next/font/google' +import Link from 'next/link' +import { notFound } from 'next/navigation' +import { Fragment } from 'react' + +const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] }) + +const TopicCard = ({ params }: Readonly<{ params: { shortName: string } }>) => { + const { shortName } = params + const { name, description } = topics[shortName] + if (!name) { + notFound() + } + + return ( + +
+ + {name} + +
{description}
+
+ + ) +} + +const getNumberOfDocumentsByTopic = (topicId: string) => { + // Filter documents by author + const filteredDocuments = Object.entries(documents) + .filter(([_, doc]) => doc.manifest.topics.includes(topicId)) + .map(([slug, doc]) => ({ slug, doc })) + + return filteredDocuments.length +} + +const Page = () => { + const sortedTopics = Object.entries(topics).sort((a, b) => { + const numDocsA = getNumberOfDocumentsByTopic(a[0]) + const numDocsB = getNumberOfDocumentsByTopic(b[0]) + return numDocsB - numDocsA + }) + + return ( +
+

+ Topics +

+
+ {sortedTopics.map((entry) => { + return ( + + + + ) + })} +
+
+ ) +} + +export default Page