mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feat(支持同步块格式的目录识别):
(cherry picked from commit 079515a157f3d0ba5cc1a92272fc16e74537f25f) feat(支持同步块格式的目录识别): 修复额外的多余目录识别问题 (cherry picked from commit c2d8ed211c16413aec37fd2438d93a7525afc03d) feat(支持同步块格式的目录识别): 去除多余的判断逻辑 (cherry picked from commit bacbe55bea13c4d3c6e79a11afcde4ba5139c67b)
This commit is contained in:
@@ -12,7 +12,7 @@ const indentLevels = {
|
||||
* H1, H2, and H3 elements.
|
||||
*/
|
||||
export const getPageTableOfContents = (page, recordMap) => {
|
||||
const contents = (page.content ?? [])
|
||||
const contents = page.content ?? []
|
||||
const toc = getBlockHeader(contents, recordMap)
|
||||
const indentLevelStack = [
|
||||
{
|
||||
@@ -69,20 +69,28 @@ function getBlockHeader(contents, recordMap, toc) {
|
||||
continue
|
||||
}
|
||||
const { type } = block
|
||||
if (type.indexOf('header') >= 0) {
|
||||
const existed = toc.find(e => e.id === blockId)
|
||||
if (!existed) {
|
||||
toc.push({
|
||||
id: blockId,
|
||||
type,
|
||||
text: getTextContent(block.properties?.title),
|
||||
indentLevel: indentLevels[type]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (block.content?.length > 0) {
|
||||
getBlockHeader(block.content, recordMap, toc)
|
||||
} else {
|
||||
if (type.indexOf('header') >= 0) {
|
||||
const existed = toc.find(e => e.id === blockId)
|
||||
if (!existed) {
|
||||
toc.push({
|
||||
id: blockId,
|
||||
type,
|
||||
text: getTextContent(block.properties?.title),
|
||||
indentLevel: indentLevels[type]
|
||||
})
|
||||
}
|
||||
} else if (type === 'transclusion_reference') {
|
||||
getBlockHeader(
|
||||
[block.format.transclusion_reference_pointer.id],
|
||||
recordMap,
|
||||
toc
|
||||
)
|
||||
} else if (type === 'transclusion_container') {
|
||||
getBlockHeader(block.content, recordMap, toc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user