react-notion-x
react-notion-x copied to clipboard
Fix: Table of contents refactor
Description
I usually organize my Notion documents into two columns: one for the content itself and another for the table of contents.
To my surprise, the headers from the left column were not appearing in the table of contents:
Upon inspecting the code, I realized that the getPageTableOfContents function only checks for the nearest children blocks of the root page and doesn't inspect sub-blocks for headers.
My changes adds the traverseBlocks function to the get-page-table-of-contents file, which recursively checks every block for headers:
Following these changes, the table of contents displays all the headers in the same way Notion does when using the two column blocks.
Notion Test Page ID
159efb60502b435496e6e37ef8e2ed6f
I'm uncertain of any potential performance impacts by checking every block this way rather than directly filtering the recordMap. Any feedback is appreciated! ❤️
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated (UTC) |
|---|---|---|---|
| react-notion-x | ✅ Ready (Inspect) | Visit Preview | Feb 6, 2024 11:48pm |
| react-notion-x-minimal-demo | ✅ Ready (Inspect) | Visit Preview | Feb 6, 2024 11:48pm |