npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@masonjames/emdash-table-of-contents

v0.1.2

Published

A delightful heading-driven table of contents plugin for EmDash CMS

Readme

EmDash Table of Contents

A polished, heading-driven table of contents plugin for EmDash CMS.

It gives editors an explicit Portable Text block for in-article placement and gives theme authors a reusable Astro component for sidebars, rails, or article headers.

Features

  • Explicit placement via a tableOfContents Portable Text block
  • Theme component for layout-driven placement
  • Nested heading support for any mix of h1h6
  • Global settings for title, heading levels, selector, minimum headings, smooth scrolling, and mobile collapse
  • Per-instance overrides for title, heading levels, selector, collapsed state, and visual variant
  • Zero storage, zero capabilities
  • Graceful fallback — when JavaScript is unavailable, content still reads cleanly and the TOC simply stays hidden

Installation

Install the package from npm:

npm install @masonjames/emdash-table-of-contents

Then register it as a trusted EmDash plugin in astro.config.mjs:

import { defineConfig } from "astro/config";
import { emdash } from "emdash/astro";
import { tableOfContentsPlugin } from "@masonjames/emdash-table-of-contents";

export default defineConfig({
	integrations: [
		emdash({
			plugins: [tableOfContentsPlugin()],
		}),
	],
});

This is the official installation path for this package today.

Usage

1. Portable Text block

Once installed, editors can insert the Table of Contents block into Portable Text content. The block exposes optional overrides for:

  • title
  • heading levels
  • target selector
  • collapsed by default
  • variant

If an override is left blank, the plugin falls back to the global plugin settings.

2. Theme component

You can also render the same TOC behavior directly from a theme:

---
import { TableOfContents } from "@masonjames/emdash-table-of-contents/astro";
---

<aside class="article-rail">
	<TableOfContents
		title="On this page"
		levels={["h2", "h3"]}
		targetSelector="article"
		variant="default"
	/>
</aside>

3. Plugin settings

The plugin auto-generates an admin settings UI from admin.settingsSchema. Available settings:

  • default heading levels
  • minimum headings before showing
  • default title
  • collapse on mobile
  • smooth scroll
  • default target selector

Behavior notes

Trusted / native plugin

This plugin uses EmDash native plugin surfaces (componentsEntry and admin.portableTextBlocks), so it is intended for trusted installation through plugins: [].

Read-only runtime config route

Current EmDash plugin APIs do not expose admin.settingsSchema values directly to site-side Astro components. To keep global settings authoritative without changing EmDash core, this plugin exposes one small public read-only route:

/_emdash/api/plugins/table-of-contents/public-config

That route returns only non-sensitive display settings.

Marketplace and emdash plugin publish

emdash plugin publish targets sandboxed marketplace bundles. EmDash currently rejects plugins that declare admin.portableTextBlocks for marketplace bundling, and sandboxed plugins cannot ship componentsEntry Astro components for site rendering.

That means this plugin is currently officially distributed as a trusted npm package, not as an EmDash Marketplace package.

Development

pnpm install
pnpm test
pnpm typecheck

Releasing

This repo is configured with an OIDC-ready GitHub Actions publish workflow.

Bootstrap the package once

For the very first publish, create the package on npm manually, then attach the GitHub workflow as the trusted publisher:

npm publish --access public --provenance=false
npm trust github @masonjames/emdash-table-of-contents --repo masonjames/emdash-table-of-contents --file publish.yml --yes

If your current npm credential cannot manage trust relationships, keep NPM_TOKEN configured in GitHub until you attach the trusted publisher from a full npm account session.

Ongoing releases

  1. bump package.json and src/types.ts to the new version
  2. run pnpm check
  3. merge the release commit to main
  4. create and push a matching stable tag such as v0.1.1
  5. GitHub Actions creates the GitHub Release and publishes to npm via OIDC trusted publishing

License

MIT