The Table of Contents for portable text and page builders
A plugin that adds a table of contents to your documents with Portable text and page builder arrays.
Install command
npm install sanity-plugin-table-of-contentsTable of Contents for your Sanity Studio
This is a plugin that adds a table of contents inspector to navigate your page builder arrays and Portable Text in documents, letting you quickly jump to a specific heading or custom block - even for nested Portable Text fields.
Features
- Table of contents inspector: Navigate your portable text in documents and quickly jump to a specific heading or custom block.
- Customisable: Choose which types and fields to include in the table of contents.
- Easy to use: Simple setup and configuration.
- Lightweight: Minimal impact on your Studio's performance.
Installation
npm install sanity-plugin-table-of-contentsUsage
Add it as a plugin in sanity.config.ts (or .js):
import { defineConfig } from 'sanity'
import { tableOfContentsPlugin } from 'sanity-plugin-table-of-contents'
export default defineConfig({
//...
plugins: [
//...
tableOfContentsPlugin({
fieldNames: ['content', 'body'], // all array and Portable Text fields that should be included in the TOC
documentTypes: ['page', 'news'], // add the TOC to specific document types
}),
],
})License
MIT © Saskia Bobinska
Develop & test
This plugin uses @sanity/plugin-kit with default configuration for build & watch scripts.
See Testing a plugin in Sanity Studio on how to run this plugin with hotreload in the studio.
Kudos
Thanks to @jordanl17 for his help getting this over the line!
Release new version
Run "CI & Release" workflow. Make sure to select the main branch and check "Release new version".
Semantic release will only release on configured branches, so it is safe to run release on any branch.
