Merge pull request #2148 from KazooTTT/feat/distinguish-tags-by-color

feat: support whether to distinguish tags by color
This commit is contained in:
tangly1024
2024-03-10 12:22:52 +08:00
committed by GitHub
3 changed files with 26 additions and 6 deletions

View File

@@ -166,6 +166,7 @@ NEXT_PUBLIC_VERSION=4.3.1
# NEXT_PUBLIC_NOTION_PROPERTY_TAGS=
# NEXT_PUBLIC_NOTION_PROPERTY_ICON=
# NEXT_PUBLIC_ENABLE_RSS=
# NEXT_PUBLIC_IS_TAG_COLOR_DISTINGUISHED=
# MAILCHIMP_LIST_ID=
# MAILCHIMP_API_KEY=
# NEXT_PUBLIC_DEBUG=

View File

@@ -12,6 +12,8 @@ const BLOG = {
APPEARANCE: process.env.NEXT_PUBLIC_APPEARANCE || 'light', // ['light', 'dark', 'auto'], // light 日间模式 dark夜间模式 auto根据时间和主题自动夜间模式
APPEARANCE_DARK_TIME: process.env.NEXT_PUBLIC_APPEARANCE_DARK_TIME || [18, 6], // 夜间模式起至时间false时关闭根据时间自动切换夜间模式
IS_TAG_COLOR_DISTINGUISHED: process.env.NEXT_PUBLIC_IS_TAG_COLOR_DISTINGUISHED === 'true' || true, // 对于名称相同的tag是否区分tag的颜色
// 3.14.1版本后,欢迎语在此配置,英文逗号隔开 , 即可支持多个欢迎语打字效果。
GREETING_WORDS: process.env.NEXT_PUBLIC_GREETING_WORDS || 'Hi我是一个程序员, Hi我是一个打工人,Hi我是一个干饭人,欢迎来到我的博客🎉',

View File

@@ -1,4 +1,5 @@
import { isIterable } from '../utils'
import BLOG from '@/blog.config'
/**
* 获取所有文章的标签
@@ -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 })
}
})
}
}
// 按照数量排序