feat: support whether to distinguish tags by color

This commit is contained in:
kazoottt
2024-03-06 19:18:36 +08:00
parent a33bf9f4d4
commit 75ec3be77e
3 changed files with 27 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import { isIterable } from '../utils'
import BLOG from '@/blog'
/**
* 获取所有文章的标签
@@ -24,14 +25,30 @@ export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
tagObj[tag] = 1
}
})
const list = []
const { IS_TAG_COLOR_DISTINGUISHED } = BLOG
if (isIterable(tagOptions)) {
tagOptions.forEach(c => {
const count = tagObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
}
})
if (!IS_TAG_COLOR_DISTINGUISHED) {
// 如果不区分颜色, 那么不同颜色相同名称的tag当做同一种tag
const savedTagNames = new Set()
tagOptions.forEach(c => {
if (!savedTagNames.has(c.value)) {
const count = tagObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
}
savedTagNames.add(c.value)
}
})
} else {
tagOptions.forEach(c => {
const count = tagObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
}
})
}
}
// 按照数量排序