refactor: aggregate tag count with contentlayer
This commit is contained in:
1
app/tag-data.json
Normal file
1
app/tag-data.json
Normal file
@ -0,0 +1 @@
|
||||
{"markdown":1,"code":1,"features":1,"next-js":5,"math":1,"ols":1,"github":1,"guide":4,"tailwind":2,"holiday":1,"canada":1,"images":1,"writings":1,"book":1,"reflection":1,"multi-author":1,"feature":1}
|
@ -1,8 +1,9 @@
|
||||
import { slug } from 'github-slugger'
|
||||
import { getAllTags, allCoreContent } from 'pliny/utils/contentlayer'
|
||||
import { allCoreContent } from 'pliny/utils/contentlayer'
|
||||
import siteMetadata from '@/data/siteMetadata'
|
||||
import ListLayout from '@/layouts/ListLayout'
|
||||
import { allBlogs } from 'contentlayer/generated'
|
||||
import tagData from 'app/tag-data.json'
|
||||
import { genPageMetadata } from 'app/seo'
|
||||
import { Metadata } from 'next'
|
||||
|
||||
@ -21,8 +22,9 @@ export async function generateMetadata({ params }: { params: { tag: string } }):
|
||||
}
|
||||
|
||||
export const generateStaticParams = async () => {
|
||||
const tags = await getAllTags(allBlogs)
|
||||
const paths = Object.keys(tags).map((tag) => ({
|
||||
const tagCounts = tagData as Record<string, number>
|
||||
const tagKeys = Object.keys(tagCounts)
|
||||
const paths = tagKeys.map((tag) => ({
|
||||
tag: tag,
|
||||
}))
|
||||
return paths
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { getAllTags } from 'pliny/utils/contentlayer'
|
||||
import Link from '@/components/Link'
|
||||
import Tag from '@/components/Tag'
|
||||
import { slug } from 'github-slugger'
|
||||
import { allBlogs } from 'contentlayer/generated'
|
||||
import tagData from 'app/tag-data.json'
|
||||
import { genPageMetadata } from 'app/seo'
|
||||
|
||||
export const metadata = genPageMetadata({ title: 'Tags', description: 'Things I blog about' })
|
||||
|
||||
export default async function Page() {
|
||||
const tags = await getAllTags(allBlogs)
|
||||
const sortedTags = Object.keys(tags).sort((a, b) => tags[b] - tags[a])
|
||||
const tagCounts = tagData as Record<string, number>
|
||||
const tagKeys = Object.keys(tagCounts)
|
||||
const sortedTags = tagKeys.sort((a, b) => tagCounts[b] - tagCounts[a])
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col items-start justify-start divide-y divide-gray-200 dark:divide-gray-700 md:mt-24 md:flex-row md:items-center md:justify-center md:space-x-6 md:divide-y-0">
|
||||
@ -19,7 +19,7 @@ export default async function Page() {
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex max-w-lg flex-wrap">
|
||||
{Object.keys(tags).length === 0 && 'No tags found.'}
|
||||
{tagKeys.length === 0 && 'No tags found.'}
|
||||
{sortedTags.map((t) => {
|
||||
return (
|
||||
<div key={t} className="mb-2 mr-5 mt-2">
|
||||
@ -29,7 +29,7 @@ export default async function Page() {
|
||||
className="-ml-2 text-sm font-semibold uppercase text-gray-600 dark:text-gray-300"
|
||||
aria-label={`View posts tagged ${t}`}
|
||||
>
|
||||
{` (${tags[t]})`}
|
||||
{` (${tagCounts[t]})`}
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
|
Reference in New Issue
Block a user