Skip to content

Commit 8cb2244

Browse files
committed
feat(支持同步块格式的目录识别):
(cherry picked from commit 079515a) feat(支持同步块格式的目录识别): 修复额外的多余目录识别问题 (cherry picked from commit c2d8ed2) feat(支持同步块格式的目录识别): 去除多余的判断逻辑 (cherry picked from commit bacbe55)
1 parent dc0a8d8 commit 8cb2244

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

lib/notion/getPageTableOfContents.js

+21-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const indentLevels = {
1212
* H1, H2, and H3 elements.
1313
*/
1414
export const getPageTableOfContents = (page, recordMap) => {
15-
const contents = (page.content ?? [])
15+
const contents = page.content ?? []
1616
const toc = getBlockHeader(contents, recordMap)
1717
const indentLevelStack = [
1818
{
@@ -69,20 +69,28 @@ function getBlockHeader(contents, recordMap, toc) {
6969
continue
7070
}
7171
const { type } = block
72-
if (type.indexOf('header') >= 0) {
73-
const existed = toc.find(e => e.id === blockId)
74-
if (!existed) {
75-
toc.push({
76-
id: blockId,
77-
type,
78-
text: getTextContent(block.properties?.title),
79-
indentLevel: indentLevels[type]
80-
})
81-
}
82-
}
83-
8472
if (block.content?.length > 0) {
8573
getBlockHeader(block.content, recordMap, toc)
74+
} else {
75+
if (type.indexOf('header') >= 0) {
76+
const existed = toc.find(e => e.id === blockId)
77+
if (!existed) {
78+
toc.push({
79+
id: blockId,
80+
type,
81+
text: getTextContent(block.properties?.title),
82+
indentLevel: indentLevels[type]
83+
})
84+
}
85+
} else if (type === 'transclusion_reference') {
86+
getBlockHeader(
87+
[block.format.transclusion_reference_pointer.id],
88+
recordMap,
89+
toc
90+
)
91+
} else if (type === 'transclusion_container') {
92+
getBlockHeader(block.content, recordMap, toc)
93+
}
8694
}
8795
}
8896

0 commit comments

Comments
 (0)