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

starlight-sphinx-loader

v2026.1.28

Published

Astro content loader for Sphinx JSON builder output - render RST docs in Starlight

Readme

starlight-sphinx-loader

An Astro content loader that consumes Sphinx JSON builder output, enabling Sphinx-based RST documentation to be rendered in Starlight without migrating away from reStructuredText.

Features

  • No RST Migration Required: Keep your existing Sphinx/RST documentation
  • Automatic Build Integration: Optionally runs sphinx-build when source files change
  • Link Rewriting: Transforms .html links to clean Starlight routes
  • Admonition Mapping: Converts Sphinx admonitions to Starlight asides
  • Sidebar Generation: Builds Starlight sidebar from Sphinx toctree
  • Code Highlighting: Preserves Pygments syntax highlighting classes

Installation

pnpm add starlight-sphinx-loader
# or
npm install starlight-sphinx-loader

Requirements

  • Astro 5.0+
  • Node.js 18+
  • Python 3.7+ with Sphinx installed

Usage

1. Configure your content collection

// src/content.config.ts
import { defineCollection } from "astro:content";
import { sphinxLoader } from "starlight-sphinx-loader";

export const collections = {
  docs: defineCollection({
    loader: sphinxLoader({
      // Path to your Sphinx source directory (contains conf.py)
      srcDir: "../path/to/sphinx/source",

      // Optional: custom output directory for JSON build
      outDir: "../path/to/sphinx/_build/json",

      // Optional: skip automatic sphinx-build (use existing JSON)
      skipBuild: false,

      // Optional: base path for generated routes
      basePath: "docs",
    }),
  }),
};

2. Build Sphinx JSON (if not using automatic build)

The loader can automatically run sphinx-build when source files change, or you can build manually:

# Using uv (recommended)
cd /path/to/sphinx/source
uv run sphinx-build -b json . ../_build/json

# Or with pip-installed sphinx
sphinx-build -b json source _build/json

3. Access content in your pages

---
// src/pages/docs/[...slug].astro
import { getCollection } from "astro:content";

export async function getStaticPaths() {
  const docs = await getCollection("docs");
  return docs.map((entry) => ({
    params: { slug: entry.id },
    props: { entry },
  }));
}

const { entry } = Astro.props;
---

<article set:html={entry.data.body} />

Loader Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | srcDir | string | required | Path to Sphinx source directory | | outDir | string | {srcDir}/_build/json | JSON output directory | | force | boolean | false | Force rebuild even if fresh | | skipBuild | boolean | false | Skip sphinx-build, use existing JSON | | basePath | string | "" | Base path for route generation | | pythonPath | string | "python3" | Python executable path | | sphinxArgs | string[] | [] | Extra sphinx-build arguments |

Schema

Each loaded entry has the following data:

{
  title: string;              // Page title
  body: string;               // Transformed HTML content
  description?: string;       // First paragraph excerpt
  toc?: string;               // Page table of contents HTML
  prev?: { link, title };     // Previous page navigation
  next?: { link, title };     // Next page navigation
  parents: { link, title }[]; // Breadcrumb trail
  sourcename?: string;        // Original RST filename
  sphinxProject?: string;     // Project name from conf.py
  sphinxVersion?: string;     // Sphinx version used
}

Sidebar Generation

The loader exports a helper to generate Starlight sidebar configuration:

import { getSphinxSidebar } from "starlight-sphinx-loader";

const sidebar = await getSphinxSidebar({
  srcDir: "../path/to/sphinx/source",
  basePath: "docs",
});

// Use in astro.config.mjs
export default defineConfig({
  integrations: [
    starlight({
      sidebar: [
        { label: "Documentation", items: sidebar },
      ],
    }),
  ],
});

HTML Transformations

The loader applies several transformations to Sphinx HTML output:

  1. Link Rewriting: .html extensions removed, paths adjusted for Starlight
  2. Admonition Conversion: Sphinx note/warning/tip → Starlight aside components
  3. Code Block Enhancement: Pygments classes mapped to standard language identifiers
  4. Sphinx Markup Cleanup: Removes paragraph markers (¶), viewcode links, etc.

Custom Styles

Include custom CSS to style Sphinx-specific elements:

/* Autodoc signatures */
.sig-name { font-weight: 600; }

/* Version badges */
.version-added { background: green; }
.version-deprecated { background: red; }

/* API documentation */
dl.py.function { border-left: 3px solid blue; }

See example/src/styles/sphinx.css for a complete stylesheet.

Example

See the example/ directory for a complete working example using Reticulum's documentation.

cd example
pnpm install
pnpm dev

License

MIT