Raw
1 import { UnistNode, UnistTree } from "types"
2 import { Transformer } from "unified"
3
4 type Options = {
5 url: string
6 }
7
8 export function addUrlToRelativeLink(options: Options): Transformer {
9 return async (tree) => {
10 const { visit } = await import("unist-util-visit")
11
12 visit(tree as UnistTree, "link", (node: UnistNode) => {
13 if (!node.url || !node.url.startsWith("/")) {
14 return
15 }
16
17 node.url = `${options.url}${node.url}`
18 })
19 }
20 }