chan.dev / posts

Create remark plugin

🌱 This post is in the growth phase. It may still be useful as it grows up.

function exchange_relative_links_with_absolute() {
return (tree) => {
visit(tree, (node) => {
if (
['link', 'definition'].includes(node?.type) &&
node.url.startsWith('/')
) {
node.url = new URL(node.url, site).toString()
}
})
}
}