支持让标签按照文章数量倒序排列

This commit is contained in:
tangly1024.com
2024-05-28 11:53:56 +08:00
parent 19bddf1fe9
commit 1614a6ed03
4 changed files with 44 additions and 14 deletions

View File

@@ -4,7 +4,7 @@ import { isIterable } from '../utils'
* 获取所有文章的标签
* @param allPosts
* @param sliceCount 默认截取数量为12若为0则返回全部
* @param tagOptions tags的下拉选项
* @param categoryOptions categories的下拉选项
* @returns {Promise<{}|*[]>}
*/
@@ -13,8 +13,14 @@ import { isIterable } from '../utils'
* @param allPosts
* @returns {Promise<{}|*[]>}
*/
export function getAllCategories({ allPages, categoryOptions, sliceCount = 0 }) {
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
export function getAllCategories({
allPages,
categoryOptions,
sliceCount = 0
}) {
const allPosts = allPages?.filter(
page => page.type === 'Post' && page.status === 'Published'
)
if (!allPosts || !categoryOptions) {
return []
}

View File

@@ -1,5 +1,5 @@
import { siteConfig } from '../config'
import { isIterable } from '../utils'
import BLOG from '@/blog.config'
/**
* 获取所有文章的标签
@@ -8,8 +8,15 @@ import BLOG from '@/blog.config'
* @param tagOptions tags的下拉选项
* @returns {Promise<{}|*[]>}
*/
export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
export function getAllTags({
allPages,
sliceCount = 0,
tagOptions,
NOTION_CONFIG
}) {
const allPosts = allPages?.filter(
page => page.type === 'Post' && page.status === 'Published'
)
if (!allPosts || !tagOptions) {
return []
@@ -27,7 +34,12 @@ export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
})
const list = []
const { IS_TAG_COLOR_DISTINGUISHED } = BLOG
const IS_TAG_COLOR_DISTINGUISHED = siteConfig(
'IS_TAG_COLOR_DISTINGUISHED',
false,
NOTION_CONFIG
)
const TAG_SORT_BY_COUNT = siteConfig('TAG_SORT_BY_COUNT', true, NOTION_CONFIG)
if (isIterable(tagOptions)) {
if (!IS_TAG_COLOR_DISTINGUISHED) {
// 如果不区分颜色, 那么不同颜色相同名称的tag当做同一种tag
@@ -52,7 +64,10 @@ export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
}
// 按照数量排序
// list.sort((a, b) => b.count - a.count)
if (TAG_SORT_BY_COUNT) {
list.sort((a, b) => b.count - a.count)
}
if (sliceCount && sliceCount > 0) {
return list.slice(0, sliceCount)
} else {