-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transform markdown links correctly (#3644)
* Revert "fix: broken link on icons readme page in patternhub (#2935)" This reverts commit 506e40c. * refactor: let's transform markdown links correctly
- Loading branch information
Showing
5 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { visit } from 'unist-util-visit'; | ||
|
||
export default function transformLinks() { | ||
return (tree) => { | ||
visit(tree, 'link', (node) => { | ||
if (node.url.endsWith('.md')) { | ||
// Remove the .md extension from the URL and transform it from camelCase to kebab-case | ||
// e.g. `customIcons.md` -> `custom-icons` | ||
// This is necessary to match the URL of the page generated by Next.js | ||
node.url = node.url | ||
.replace(/\.md$/, '') | ||
.replaceAll(/([a-z])([A-Z])/g, '$1-$2') | ||
.toLowerCase(); | ||
} | ||
}); | ||
}; | ||
} |