Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transform markdown links correctly #3644

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});
};
}
Loading