Skip to content

Commit

Permalink
feat: transform markdown links correctly (#3644)
Browse files Browse the repository at this point in the history
* 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
mfranzke authored Jan 7, 2025
1 parent 3930514 commit 2dd94c9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/foundations/docs/Icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ You could use the CSS Custom Property `--db-icon-color` to overwrite the icons c

If you have custom icons and want to use them for foundations and/or in components, you need to generate a **woff2** file.

[More information](https://github.com/db-ui/mono/blob/main/packages/foundations/docs/CustomIcons.md)
[More information](./CustomIcons.md)
3 changes: 2 additions & 1 deletion showcases/patternhub/next.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import remarkGfm from 'remark-gfm';
import generated from '@next/mdx';
import rehypeSlug from 'rehype-slug';
import remarkTransformLinks from './scripts/remark-transform-links.js';

const withMDX = generated({
extension: /\.mdx?$/,
options: {
remarkPlugins: [remarkGfm],
remarkPlugins: [remarkGfm, remarkTransformLinks],
rehypePlugins: [rehypeSlug],
providerImportSource: '@mdx-js/react'
}
Expand Down
3 changes: 2 additions & 1 deletion showcases/patternhub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"iframe-resizer": "^5.3.2",
"open-cli": "^8.0.0",
"sass": "1.77.4",
"typescript": "5.4.5"
"typescript": "5.4.5",
"unist-util-visit": "^5.0.0"
}
}
17 changes: 17 additions & 0 deletions showcases/patternhub/scripts/remark-transform-links.js
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();
}
});
};
}

0 comments on commit 2dd94c9

Please sign in to comment.