Skip to content

Remark plugin to prepend an absolute url to relative links

License

Notifications You must be signed in to change notification settings

alxjpzmn/remark-prepend-url

Repository files navigation

remark-prepend-url

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.

Install

npm install remark-prepend-url

Use

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.

TypeScript

remark-prepend-url contains TypeScript type definitions. The package is ready for use with TypeScript.

License

Distributed under the MIT License.

About

Remark plugin to prepend an absolute url to relative links

Topics

Resources

License

Stars

Watchers

Forks