From 888496b3cc2c862507b5efcd2a7157fbb49ed3a1 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 25 Apr 2022 16:02:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A9=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllCategories.js | 16 ++++++++++------ lib/notion/getAllTags.js | 17 ++++++++++------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/notion/getAllCategories.js b/lib/notion/getAllCategories.js index 61aab49c..b9a543d8 100644 --- a/lib/notion/getAllCategories.js +++ b/lib/notion/getAllCategories.js @@ -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) diff --git a/lib/notion/getAllTags.js b/lib/notion/getAllTags.js index 3ac01f54..174055d1 100644 --- a/lib/notion/getAllTags.js +++ b/lib/notion/getAllTags.js @@ -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)