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

astro-toc-smol

v0.1.0

Published

Astro integration: generates TOC HTML from final rendered page at build time

Readme

astro-toc-smol

Astro integration that generates table-of-contents HTML from the final rendered page at build time, rather than extracting headings from MDX frontmatter or building the TOC in the browser with JavaScript.

Why

Astro's built-in heading extraction reads the MDX AST before components render, so headings generated by imported components, conditional blocks, or non-MDX content can be missed. Client-side TOC scripts fix coverage but add layout shift and depend on the DOM being ready. This plugin runs as a Vite transformIndexHtml hook after every framework component and layout has rendered, injecting the completed TOC directly into the HTML.

Installation

npm install astro-toc-smol

Setup

// astro.config.ts
import astroToc from 'astro-toc-smol';

export default defineConfig({
  integrations: [
    astroToc(),
  ],
});

Your layout must also render the placeholder nav when serverToc is true. If you use the FusionAuth docs TOC.astro component, pass serverToc={frontmatter.serverToc} and it handles this automatically. For custom layouts, render:

<nav id="toc-container" data-server-toc data-max-depth="4"></nav>

The plugin finds this element, fills it with the generated TOC, and removes both data attributes before the page is written.

Usage

Add serverToc: true to any page's frontmatter:

---
title: My Page
serverToc: true
---

No JavaScript, TOC is in the HTML when the page loads. A lightweight scroll-spy script (shipped by TOC.astro) handles the active-link highlighting at runtime.

Options

astroToc({
  // CSS selector(s) for the content area to scan for headings.
  // Tried in order; falls back to the full document if none match.
  // Default: ['article.fusion-article section', 'article.fusion-article', 'article', 'main']
  articleSelector: 'article.fusion-article section',
})

articleSelector can be a string or an array of strings.

How it works

  1. A Vite transformIndexHtml hook runs on every generated HTML file.
  2. If the page contains data-server-toc, the HTML is parsed with node-html-parser.
  3. Headings (h2h6) and API endpoint markers ([data-toc-type="api"]) are collected from the article element in document order.
  4. The same nested <ul> structure used by the client-side TOC is built server-side and injected into the placeholder nav.
  5. The placeholder attributes are removed and the modified HTML is returned.

TOC HTML structure

The generated markup mirrors TOC.astro's clientToc output so the same Tailwind classes and scroll-spy selectors work unchanged:

<ul id="toc-list" class="space-y-3 pt-5" data-widget="scroll-spy">
  <li>
    <div class="group" data-widget="scroll-spy-item">
      <a href="#overview" class="block font-medium text-slate-600 text-sm ...">Overview</a>
    </div>
    <ul class="space-y-3 ml-4 pt-3" data-widget="scroll-spy">
      <li>
        <div class="group" data-widget="scroll-spy-item">
          <a href="#sub-section" class="...">Sub Section</a>
        </div>
      </li>
    </ul>
  </li>
</ul>

API headings (data-toc-type="api") are rendered with a coloured method badge:

<a href="#get-api-users" class="block font-mono text-xs ...">
  <span class="font-bold ... text-yellow-600">GET</span>
  <span>/api/users</span>
</a>

Controlling depth

Set data-max-depth on the placeholder nav (or pass maxDepth to TOC.astro) to limit how many heading levels appear:

<nav id="toc-container" data-server-toc data-max-depth="3"></nav>

Default is 4 (h2–h5).