NotionX / react-notion-x

Fast and accurate React renderer for Notion. TS batteries included. ⚡️
https://react-notion-x-demo.transitivebullsh.it
MIT License
4.69k stars 544 forks source link

Fix: Table of contents refactor #540

Open DiegoxK opened 5 months ago

DiegoxK commented 5 months ago

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: Screenshot 2024-02-06 173013

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:

Screenshot 2024-02-06 183837

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! ❤️

vercel[bot] commented 5 months ago

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