feature:

新增标签汇总页
This commit is contained in:
tangly1024
2021-11-11 17:01:17 +08:00
parent 635735c4e5
commit fcb4409af8
9 changed files with 71 additions and 22 deletions

View File

@@ -1,11 +1,11 @@
import { rest } from "lodash"
/**
* 获取所有文章的标签
* @param allPosts
* @param sliceCount 默认截取数量为12若为0则返回全部
* @returns {Promise<{}|*[]>}
*/
export async function getAllTags (allPosts) {
export async function getAllTags (allPosts, sliceCount = 12) {
if (!allPosts) {
return []
}
@@ -24,7 +24,13 @@ export async function getAllTags (allPosts) {
})
// 按照标签数量排序
const list = Object.keys(tagObj).map((index) => {return {name:index,count:tagObj[index]}})
const list = Object.keys(tagObj).map((index) => {
return { name: index, count: tagObj[index] }
})
list.sort((a, b) => b.count - a.count)
return list
if (sliceCount) {
return list.slice(0, 12)
} else {
return list
}
}