Raw
1 import { UnistNode, UnistTree } from "types"
2 import { Transformer } from "unified"
3
4 export const changeLinksToHtmlMdPlugin = (): Transformer => {
5 return async (tree) => {
6 const { visit } = await import("unist-util-visit")
7
8 visit(tree as UnistTree, ["link"], (node: UnistNode) => {
9 if (
10 node.type === "link" &&
11 node.url?.startsWith("https://docs.medusajs.com") &&
12 !node.url.endsWith("index.html.md") &&
13 !node.url.includes("/api/store") &&
14 !node.url.includes("/api/admin")
15 ) {
16 node.url += `/index.html.md`
17 }
18 })
19 }
20 }