修复空数据编译问题

This commit is contained in:
tangly1024
2022-04-25 16:02:04 +08:00
parent 87440ea140
commit 888496b3cc
2 changed files with 20 additions and 13 deletions

View File

@@ -1,9 +1,11 @@
import { isIterable } from '../utils'
/**
* 获取所有文章的分类
* @param allPosts
* @returns {Promise<{}|*[]>}
*/
export async function getAllCategories ({ allPosts, categoryOptions, sliceCount = 0 }) {
export async function getAllCategories({ allPosts, categoryOptions, sliceCount = 0 }) {
if (!allPosts || !categoryOptions) {
return []
}
@@ -19,12 +21,14 @@ export async function getAllCategories ({ allPosts, categoryOptions, sliceCount
}
})
const list = []
categoryOptions.forEach(c => {
const count = categoryObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
if (isIterable(categoryOptions)) {
for (const c of categoryOptions) {
const count = categoryObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
}
}
})
}
// 按照数量排序
// list.sort((a, b) => b.count - a.count)

View File

@@ -1,3 +1,4 @@
import { isIterable } from '../utils'
/**
* 获取所有文章的标签
@@ -6,7 +7,7 @@
* @param tagOptions tags的下拉选项
* @returns {Promise<{}|*[]>}
*/
export async function getAllTags ({ allPosts, sliceCount = 0, tagOptions }) {
export async function getAllTags({ allPosts, sliceCount = 0, tagOptions }) {
if (!allPosts || !tagOptions) {
return []
}
@@ -22,12 +23,14 @@ export async function getAllTags ({ allPosts, sliceCount = 0, tagOptions }) {
}
})
const list = []
tagOptions.forEach(c => {
const count = tagObj[c.value]
if (count) {
list.push({ id: c.id, name: c.value, color: c.color, count })
}
})
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 })
}
})
}
// 按照数量排序
// list.sort((a, b) => b.count - a.count)