This is a simple remark plugin that allows you to prepend an absolute url (https://acme.com
) to relative links (/posts
).
Useful if you're using a static site generator like Astro with .mdx
files and you'd like to prepare them for a full-text RSS feed.
npm install remark-prepend-url
remark().use(remarkPrependUrl, new URL("https://acme.com"));
Given the following example.md
...a [link]('/posts') for you.
Using remark-prepend-url
like below:
import rehypeStringify from "rehype-stringify";
import remarkParse from "remark-parse";
import { read } from "to-vfile";
import { unified } from "unified";
const file = await unified()
.use(remarkParse)
.use(remarkPrependUrl, new URL("https://acme.com"))
.use(remarkStringify)
.process(await read("example.md"));
console.log(String(file));
will yield:
...a [link]('https://acme.com/posts') for you.
remark-prepend-url
contains TypeScript type definitions. The package is ready for use with TypeScript.
Distributed under the MIT License.