Skip to content

Commit 49d53ab

Browse files
committed
Fix link transformer
1 parent 0f09d35 commit 49d53ab

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

remark/rehype-link-transformer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { existsSync } from "fs";
1+
import { existsSync } from "node:fs";
2+
import { basename } from "node:path";
3+
import url from "node:url";
24
import { visit } from "unist-util-visit";
3-
import url from "url";
45

56

67
const rehypeLinkTransformer = () => (tree, vfile) => {
78
visit(tree, "element", (node) => {
89
if (node.tagName === "a") {
910
const href = url.parse(node.properties.href);
1011
if (href.hostname === null && href.pathname?.endsWith(".md") && existsSync(vfile.history[0])) {
11-
href.pathname = href.pathname.replace(/.md$/, ".html");
12+
href.pathname = basename(href.pathname).replace(/.md$/, ".html");
1213
node.properties.href = url.format(href);
1314
}
1415
}

0 commit comments

Comments
 (0)