Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Seeking help to generate a table of contents for a blog post using portable text and block-content-to-react.

8 replies
Last updated: Jul 1, 2020
Hi everyone. I want to create table of content for a blog post and I'm using portable text to render the post using block-content-to-react. Is there a plugin/lib that can generate that from the portable text ? I couldn't find one. Has anyone else already solved this ?
Jun 30, 2020, 8:07 PM
user Y
yeah something like this....the links are not working on clicking in the codesandbox...but I get the idea. Thanks !
Jun 30, 2020, 8:21 PM
It’s because it’s in a iframe I think. Should work in the standalone window :)
Jun 30, 2020, 8:24 PM
user Y
This might be a bug
Jun 30, 2020, 10:35 PM
If you add a list in block content under h2 it is still showing in the serialized component even when I'm returning null for everything except header tags
Jun 30, 2020, 10:36 PM
user Y
This might be a BUG. I'm using the above example and If I add a list after header tag no matter where ...it shows up in the serialized content even though I'm returning
null
for everything except header tags in
ToCserializer
.
I reproduced it here :
https://codesandbox.io/s/linked-headings-with-portable-text-and-react-zy487?file=/src/index.js
Jun 30, 2020, 10:50 PM
user M
can u help with ^ ? Am I doing something wrong or is this a bug?
Jul 1, 2020, 5:53 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?