javascript - 如何在 Next.js 中使用 tailwind css 构建词云/标签云
问题描述
我有以下数据结构。对于每个标签,我们都有该标签在博客文章中使用的次数。
tags = {
go: 12,
html: 6,
js: 9,
.....
}
目前我正在考虑使用地图功能来构建标签云。
export default function TagCloud({ tags }) {
const tagCount = Object.keys(tags).length;
return (
<div className="flex flex-row flex-wrap content-around items-center align-middle w-full">
{Object.entries(tags).map((t) => {
const slug = t[0].toLowerCase().replace(" ", "-").replace("/", "-");
return (
<Link key={slug} href={`/blog/tags/${slug}`}>
<a
className={cn("p-1 mx-1 hover:underline hover:text-gray-600", {
"text-xs": t[1],
"text-sm": t[1],
"text-base": t[1],
"text-lg": t[1],
"text-xl": t[1],
"text-2xl": t[1],
"text-3xl": t[1],
})}
>
{t[0]}
</a>
</Link>
);
})}
</div>
);
}
t[1]
结合使用我们tagCount
需要在地图之前捕获的其他值,然后我们应该能够定义tailwind-css
类名来定义字体大小。但是,我一直在思考如何定义要使用的类名的公式。
其次,根据使用标签的次数和使用了多少不同的标签,我们可能还需要或多或少地改变标签大小,就像我目前在代码中那样。我认为使用类名库这将最容易定义标签是否应该获得某个类名。
我是否过于简化了我试图实现的目标?
解决方案
推荐阅读
- ios - 沿画线放置 UILabel
- react-native - 在子视图中获取 apollo 客户端以手动使用查询
- python - 获取嵌套字典中字典值的数量
- java - 从 url 读取 csv 文件
- r - 如何在软件 R 中没有“for”的情况下高效编程?
- php - 为什么 wp 动作钩子不适用于基于特定 url 字符串删除短代码的函数
- visual-studio - 如何在 Visual Studio 解决方案中升级 CUDA 版本?
- mysql - findAllUseCountTop1ByIsActiveOrderById(Boolean isActive) 不会生成带有“LIMIT 1”的查询
- c++ - 使用 std::enable_if 的多变量模板特化
- sql - 谷歌表格查询功能不在