rehype-autolink
v1.0.0
Published
An Astro + Rehype plugin that auto-links text phrases in blog posts based on a JSON config file.
Maintainers
Readme
rehype-autolink
An Astro + Rehype plugin that automatically links phrases in your blog posts based on a JSON config file.
Installation
npm install rehype-autolinkUsage (Astro)
In your astro.config.mjs (or .ts):
import { defineConfig } from "astro/config";
import { rehypeAutoLink } from "rehype-autolink";
export default defineConfig({
markdown: {
rehypePlugins: [
[rehypeAutoLink, "./src/data/linkData.json"]
]
}
});./src/data/linkData.jsonis your JSON config file with link rules.
JSON Format
{
"maxLinks": 5,
"entries": [
{
"id": "forex-broker",
"href": "/brokers/forex",
"maxOccurrences": 2,
"texts": [
{ "id": "t1", "text": "Forex broker" },
{ "id": "t2", "text": "broker" }
]
}
]
}maxLinks= global max links allowed per page- Each
entry= target link rule texts= variations of the phrase to linkmaxOccurrences= per-entry limit
License
MIT
