标签排序

奖赏按钮
搜索框按钮加载动画
EndSlogan排版
notion-viewport处理
This commit is contained in:
tangly
2021-11-06 15:19:38 +08:00
parent a4d051fa38
commit add1c677e3
9 changed files with 42 additions and 54 deletions

View File

@@ -1,3 +1,5 @@
import { rest } from "lodash"
/**
* 获取所有文章的标签
* @param allPosts
@@ -10,6 +12,8 @@ export async function getAllTags (allPosts) {
let tags = allPosts.map(p => p.tags)
tags = [...tags.flat()]
// 标签计数
const tagObj = {}
tags.forEach(tag => {
if (tag in tagObj) {
@@ -18,5 +22,9 @@ export async function getAllTags (allPosts) {
tagObj[tag] = 1
}
})
return tagObj
// 按照标签数量排序
const list = Object.keys(tagObj).map((index) => {return {name:index,count:tagObj[index]}})
list.sort((a, b) => b.count - a.count)
return list
}