Skip to content

Commit 2d44929

Browse files
Refactor markdown extension removal logic
Support for `.md`, `.mdx`, and `index.md(x)` variations. This should make it easier to link things moving forward.
1 parent 304c9f2 commit 2d44929

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/plugins/remove-markdown-extensions.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ export default function removeMarkdownExtensions(): (tree: Node) => void {
1919
node.properties &&
2020
typeof node.properties.href === "string"
2121
) {
22-
const markdownExtensionRegex = /\.md(#.*)?$/;
23-
if (markdownExtensionRegex.test(node.properties.href)) {
22+
const match = /(?:\/index)?\.(md|mdx)(#.*)?$/;
23+
if (match.test(node.properties.href)) {
2424
let date = new Date().toLocaleTimeString("en-US", { hour12: false });
25+
2526
console.log(
26-
`\x1b[90m${date}\x1b[0m \x1b[95m[🔥 *.md]\x1b[0m ${node.properties.href}`,
27+
`\x1b[90m${date}\x1b[0m \x1b[95m[🔥 *.md(x)]\x1b[0m ${node.properties.href}`,
2728
);
2829

29-
node.properties.href = node.properties.href.replace(
30-
markdownExtensionRegex,
31-
"$1",
32-
);
30+
node.properties.href = node.properties.href.replace(match, "$2");
3331
}
3432
}
3533
});

0 commit comments

Comments
 (0)