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

rehype-auto-internal-links

v0.1.0

Published

Rehype plugin that auto-converts keywords to internal links — ideal for content sites, wikis, and documentation

Downloads

85

Readme

rehype-auto-internal-links

A rehype plugin that automatically converts occurrences of registered keywords into internal anchor links across your content pages.

Ideal for content-heavy sites: encyclopedias, wikis, documentation, blogs — anywhere you want terms to link to their definition pages without writing <a> tags by hand.


How it works

At build time you provide a keyword map — an object mapping lowercase keywords to their URLs:

{
  "burn rate": { href: "/glossary/burn-rate" },
  "product-market fit": { href: "/glossary/pmf" },
  "runway": { href: "/glossary/runway" },
}

The plugin walks the HTML AST of each page and replaces matching text nodes with <a> elements. It follows a set of sensible rules so the result is clean and non-intrusive.

Rules

  • Each keyword is linked at most once per page
  • Total links added per page is capped at maxLinksPerPage (default: 3)
  • Never links inside <a>, <code>, <pre>, <h1><h6>, <script>, <style>, <button>
  • Never self-links (a page never links to itself)
  • Longer keywords match before shorter substrings (e.g. "product-market fit" wins over "product")
  • Case-insensitive match; anchor text preserves the original casing from the source

Install

npm install rehype-auto-internal-links

Peer dependency — make sure unist-util-visit is available (it ships with Astro and most unified setups):

npm install unist-util-visit

Usage

Option A — Manual keyword map

Provide your own map. Works with any framework that supports rehype plugins.

import { rehypeAutoInternalLinks } from 'rehype-auto-internal-links';

const keywordMap = {
  'burn rate': { href: '/glossary/burn-rate' },
  'runway':    { href: '/glossary/runway' },
  'arr':       { href: '/glossary/arr' },
};

// In a unified pipeline:
unified()
  .use(rehypeParse)
  .use(rehypeAutoInternalLinks, { keywordMap, maxLinksPerPage: 3 })
  .use(rehypeStringify)
  .process(html);

Option B — Astro with auto-generated map

Use the included buildKeywordMap helper to automatically scan your Markdown/MDX content files at build time. It reads the primaryKeyword frontmatter field from each file.

// astro.config.mjs
import { defineConfig } from 'astro/config';
import { rehypeAutoInternalLinks } from 'rehype-auto-internal-links';
import { buildKeywordMap } from 'rehype-auto-internal-links/build-keyword-map';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));

const keywordMap = buildKeywordMap({
  contentRoot: resolve(__dirname, 'src/content'),
  // sections defaults to ['glossary', 'guides', 'concepts', 'articles']
  // locale defaults to 'en'
});

export default defineConfig({
  markdown: {
    rehypePlugins: [
      [rehypeAutoInternalLinks, { keywordMap, maxLinksPerPage: 2 }],
    ],
  },
});

Then in your content frontmatter:

---
title: "Burn Rate"
primaryKeyword: "burn rate"
---

The helper will register "burn rate" → /glossary/burn-rate automatically.


API

rehypeAutoInternalLinks(options)

| Option | Type | Default | Description | |--------|------|---------|-------------| | keywordMap | Record<string, { href: string }> | {} | Map of keywords to their target URLs | | maxLinksPerPage | number | 3 | Maximum number of links to inject per page |

buildKeywordMap(options) (Astro / filesystem helper)

Import from rehype-auto-internal-links/build-keyword-map.

| Option | Type | Default | Description | |--------|------|---------|-------------| | contentRoot | string | — | Required. Absolute path to the content root directory | | sections | string[] | ['glossary', 'guides', 'concepts', 'articles'] | Subdirectory names to scan | | locale | string | 'en' | Locale subfolder inside each section. Pass '' to disable. |


License

MIT