@plugdash/tocgen

The EmDash alternative to Table of Contents Plus

Long posts shouldn't make readers work to find what they need.

320 words·2min read

Parses headings from your Portable Text content and writes a nested navigation structure on every publish. Ships TableOfContents.astro with a sticky sidebar variant that follows readers as they scroll. Works out of the box. Skips short posts automatically.

npm install @plugdash/tocgen
betaGitHub

Setup

  1. Install and register

    bash
    npm install @plugdash/tocgen
    js
    import tocgen from "@plugdash/tocgen"
    // in emdash plugins array:
    tocgen({ minHeadings: 3 })
  2. Add to your layout

    astro
    import TableOfContents from "@plugdash/tocgen/TableOfContents.astro"
    
    <TableOfContents post={post} sticky />

After this, every post with three or more headings gets a table of contents. Short posts are skipped - you don't need to configure the threshold.

It looks right. But it's yours to change.

Props

proptypedefaultdescription
postEmDash content itemRequired
stickybooleanfalseStick to viewport while scrolling
maxDepth2 | 3 | 43Deepest heading level to include

CSS custom properties

tokendescription
--plugdash-toc-sizeFont size
--plugdash-toc-indentNested indent
--plugdash-toc-hoverHover colour

Components are intentionally simple. Copy src/TableOfContents.astrointo your theme and modify freely - no upstream coupling.

Pairs well with

readers who can see the structure and the time commitment are more likely to start.

beta

Readers decide in three seconds. Give them a reason to stay.

npm install @plugdash/readtime
beta

The block every technical writer reaches for that almost no theme ships.

npm install @plugdash/callout
built with plugdash.dev