Skip to content

Commit

Permalink
Merge pull request #3041 from qixing-jk/sync_block_catalogue
Browse files Browse the repository at this point in the history
feat(支持同步块格式的目录识别):
  • Loading branch information
tangly1024 authored Dec 21, 2024
2 parents 2ccaf73 + 8cb2244 commit 0967722
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/notion/getPageTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 0967722

Please sign in to comment.