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

How to exclude bullet points from the table of contents in a blog using Sanity and NextJs.

14 replies
Last updated: Aug 12, 2021
help 👌Hello, please does anyone have an idea about how I can add ✔️`table of content`✔️ to my blog with
sanity
and
NextJs
.Something like this.
Aug 11, 2021, 7:06 PM
Thanks so much
Aug 11, 2021, 8:31 PM
user Y
Please how do I exclude the bullet points from the table of content
Aug 11, 2021, 9:12 PM
I think you can filter on
level == 1
Aug 11, 2021, 9:14 PM
Or maybe I’m misunderstanding? Maybe you want to wrap it in
<ol>
 instead?
Aug 11, 2021, 9:16 PM
No I have these bullet points I created in sanity studio and they are also appearing below the
You might like this
Aug 11, 2021, 9:31 PM
No, I created some bullet points in sanity studio and they are also showing. That's below the
You might like this
Aug 11, 2021, 9:33 PM
I don’t have enough context to be helpful here. How does the JSON document of this post look like?
Aug 11, 2021, 9:36 PM

    {
      "_key": "a0392cd68b8d",
      "_type": "block",
      "children": [
        {
          "_key": "917c006759dc",
          "_type": "span",
          "marks": [
            "d84dd0a78456"
          ],
          "text": "Sidebar Menu with html css"
        }
      ],
      "level": 1,
      "listItem": "bullet",
      "markDefs": [
        {
          "_key": "d84dd0a78456",
          "_type": "internalLink",
          "reference": {
            "_ref": "4ae667f2-5f9d-4b3d-9616-429aa1616867",
            "_type": "reference"
          }
        }
      ],
      "style": "normal"
    },
Aug 11, 2021, 9:53 PM
Sorry I could only copy some part because the whole json is too long and slack won't allow me to send it
Aug 11, 2021, 9:54 PM
I see that the bullets have level set to 1 on them. But I can't find the level property on the node
Aug 11, 2021, 10:26 PM
@knut (he/him) Hi I added some ordered list to your codeSandBox and it was also included in the table of content. Please how do I exclude the ordered list?
Aug 12, 2021, 12:37 PM
Maybe you could fork my codesandbox and insert your JSON document there?
Aug 12, 2021, 12:44 PM
user Y
No, It seems you don't understand what I meant. Your code works correctly but in your case, there weren't any bullet points in your content. Am trying to say that when there is a bullet point in the content it also gets added to the table of content which is not what I wanted. I only want the h1,h2,h3,h4 to show excluding the bullet points.
Aug 12, 2021, 1:13 PM
user Y
Please don't worry I have figured it out. Thanks for helpingđź‘Ś
Aug 12, 2021, 3:59 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?