mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-04 07:26:47 +00:00
fix(修复隐藏文章中无法显示只存在于隐藏文章中的标签的问题):
具体问题为:对于新打的标签,无法在隐藏文章里显示,只能显示之前添加好的旧标签。而将文章设置为公开,就能全部显示。 Closes #3322 #3038 #3137
This commit is contained in:
@@ -332,8 +332,6 @@ function handleDataBeforeReturn(db) {
|
|||||||
db.notice = cleanBlock(db?.notice)
|
db.notice = cleanBlock(db?.notice)
|
||||||
delete db.notice?.id
|
delete db.notice?.id
|
||||||
}
|
}
|
||||||
|
|
||||||
db.tagOptions = cleanIds(db?.tagOptions)
|
|
||||||
db.categoryOptions = cleanIds(db?.categoryOptions)
|
db.categoryOptions = cleanIds(db?.categoryOptions)
|
||||||
db.customMenu = cleanIds(db?.customMenu)
|
db.customMenu = cleanIds(db?.customMenu)
|
||||||
|
|
||||||
@@ -344,6 +342,8 @@ function handleDataBeforeReturn(db) {
|
|||||||
db.allNavPages = cleanPages(db?.allNavPages, db.tagOptions)
|
db.allNavPages = cleanPages(db?.allNavPages, db.tagOptions)
|
||||||
db.allPages = cleanPages(db.allPages, db.tagOptions)
|
db.allPages = cleanPages(db.allPages, db.tagOptions)
|
||||||
db.latestPosts = cleanPages(db.latestPosts, db.tagOptions)
|
db.latestPosts = cleanPages(db.latestPosts, db.tagOptions)
|
||||||
|
// 必须在使用完毕后才能进行清理
|
||||||
|
db.tagOptions = cleanTagOptions(db?.tagOptions)
|
||||||
|
|
||||||
const POST_SCHEDULE_PUBLISH = siteConfig(
|
const POST_SCHEDULE_PUBLISH = siteConfig(
|
||||||
'POST_SCHEDULE_PUBLISH',
|
'POST_SCHEDULE_PUBLISH',
|
||||||
@@ -464,6 +464,22 @@ function cleanIds(items) {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理和过滤tagOptions
|
||||||
|
* @param {*} tagOptions
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function cleanTagOptions(tagOptions) {
|
||||||
|
if (tagOptions && Array.isArray(tagOptions)) {
|
||||||
|
return deepClone(
|
||||||
|
tagOptions
|
||||||
|
.filter(tagOption => tagOption.source === 'Published')
|
||||||
|
.map(({ id, source, ...newTagOption }) => newTagOption)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return tagOptions
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理block数据
|
* 清理block数据
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,23 +14,38 @@ export function getAllTags({
|
|||||||
tagOptions,
|
tagOptions,
|
||||||
NOTION_CONFIG
|
NOTION_CONFIG
|
||||||
}) {
|
}) {
|
||||||
|
// 保留Invisible的Page中的Tags,最后再过滤掉
|
||||||
const allPosts = allPages?.filter(
|
const allPosts = allPages?.filter(
|
||||||
page => page.type === 'Post' && page.status === 'Published'
|
page =>
|
||||||
|
page.type === 'Post' &&
|
||||||
|
(page.status === 'Published' || page.status === 'Invisible')
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!allPosts || !tagOptions) {
|
if (!allPosts || !tagOptions) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
// 计数
|
// Tag数据统计
|
||||||
let tags = allPosts?.map(p => p.tags)
|
const AllTagInfos = {}
|
||||||
tags = [...tags.flat()]
|
// 遍历所有文章
|
||||||
const tagObj = {}
|
allPosts.forEach(post => {
|
||||||
tags.forEach(tag => {
|
post.tags.forEach(tag => {
|
||||||
if (tag in tagObj) {
|
// 如果标签已经存在
|
||||||
tagObj[tag]++
|
if (AllTagInfos[tag]) {
|
||||||
} else {
|
if (
|
||||||
tagObj[tag] = 1
|
AllTagInfos[tag].source === 'Invisible' &&
|
||||||
}
|
post.status === 'Published'
|
||||||
|
) {
|
||||||
|
AllTagInfos[tag].source = post.status
|
||||||
|
}
|
||||||
|
AllTagInfos[tag].count++
|
||||||
|
} else {
|
||||||
|
// 如果标签不存在,创建一个新的标签对象
|
||||||
|
AllTagInfos[tag] = {
|
||||||
|
count: 1,
|
||||||
|
source: post.status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const list = []
|
const list = []
|
||||||
@@ -46,18 +61,18 @@ export function getAllTags({
|
|||||||
const savedTagNames = new Set()
|
const savedTagNames = new Set()
|
||||||
tagOptions.forEach(c => {
|
tagOptions.forEach(c => {
|
||||||
if (!savedTagNames.has(c.value)) {
|
if (!savedTagNames.has(c.value)) {
|
||||||
const count = tagObj[c.value]
|
const tagInfo = AllTagInfos[c.value]
|
||||||
if (count) {
|
if (tagInfo) {
|
||||||
list.push({ id: c.id, name: c.value, color: c.color, count })
|
list.push({ id: c.id, name: c.value, color: c.color, ...tagInfo })
|
||||||
}
|
}
|
||||||
savedTagNames.add(c.value)
|
savedTagNames.add(c.value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
tagOptions.forEach(c => {
|
tagOptions.forEach(c => {
|
||||||
const count = tagObj[c.value]
|
const tagInfo = AllTagInfos[c.value]
|
||||||
if (count) {
|
if (tagInfo) {
|
||||||
list.push({ id: c.id, name: c.value, color: c.color, count })
|
list.push({ id: c.id, name: c.value, color: c.color, ...tagInfo })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user