import Link from "next/link" import { getPagesUnderRoute } from "nextra/context" import { Tag, Card } from "@/components" import NextLink from "next/link" import { useRouter } from "next/router" import { clsx } from "clsx"
export default function Blog() { const { asPath } = useRouter() const items = getPagesUnderRoute("/blog").flatMap(item => item.children || item) const blogs = items.sort( (a, b) => b.frontMatter.date - a.frontMatter.date, ) const currentTag = asPath.startsWith("/blog") ? "" : asPath.replace("/tags/", "").replace(//$/, "") // const tags = blogs .flatMap(blog => blog.frontMatter.tags) .reduce((acc, tag) => { acc[tag] ||= 0 acc[tag] += 1 return acc }, {}) // const tagList = (
{Object.entries(tags)
.sort((a, b) => b[1] - a[1])
.map(([tag, count]) => (
<NextLink
key={tag}
href={currentTag === tag ? "/blog" :
)
//
const blogList = blogs.map(
page =>
(!currentTag || page.frontMatter.tags.includes(currentTag)) && (
/tags/${tag}
}
data-active={currentTag === tag ? "" : undefined}
className={clsx("tag [&[data-active]]:bg-primary capitalize")}
>
{tag.replaceAll("-", " ")} ({count})
))}
{page.frontMatter.tags.map(tag => (
{tag.replaceAll("-", " ")}
))}
{page.frontMatter.title}
{page.frontMatter.date.toLocaleDateString("en", {
month: "long",
day: "numeric",
year: "numeric",
})}
by {page.frontMatter.byline}
Read more →
),
)
return (
<>
{blogList}
</>
)
}