mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 23:16:47 +00:00
修复错误的标签
This commit is contained in:
@@ -113,9 +113,47 @@ function handleDataBeforeReturn(db) {
|
||||
db.allNavPages = shortenIds(db?.allNavPages)
|
||||
// db.allPages = cleanBlocks(db?.allPages)
|
||||
|
||||
db.allNavPages = cleanPages(db?.allNavPages, db.tagOptions)
|
||||
db.allPages = cleanPages(db.allPages, db.tagOptions)
|
||||
db.latestPosts = cleanPages(db.latestPosts, db.tagOptions)
|
||||
return db
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理文章列表中的异常数据
|
||||
* @param {Array} allPages - 所有页面数据
|
||||
* @param {Array} tagOptions - 标签选项
|
||||
* @returns {Array} 处理后的 allPages
|
||||
*/
|
||||
function cleanPages(allPages, tagOptions) {
|
||||
// 校验参数是否为数组
|
||||
if (!Array.isArray(allPages) || !Array.isArray(tagOptions)) {
|
||||
console.warn('Invalid input: allPages and tagOptions should be arrays.')
|
||||
return allPages || [] // 返回空数组或原始值
|
||||
}
|
||||
|
||||
// 提取 tagOptions 中所有合法的标签名
|
||||
const validTags = new Set(
|
||||
tagOptions
|
||||
.map(tag => (typeof tag.name === 'string' ? tag.name : null))
|
||||
.filter(Boolean) // 只保留合法的字符串
|
||||
)
|
||||
|
||||
// 遍历所有的 pages
|
||||
allPages.forEach(page => {
|
||||
// 确保 tagItems 是数组
|
||||
if (Array.isArray(page.tagItems)) {
|
||||
// 对每个 page 的 tagItems 进行过滤
|
||||
page.tagItems = page.tagItems.filter(
|
||||
tagItem =>
|
||||
validTags.has(tagItem?.name) && typeof tagItem.name === 'string' // 校验 tagItem.name 是否是字符串
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
return allPages
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理一组数据的id
|
||||
* @param {*} items
|
||||
|
||||
Reference in New Issue
Block a user