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

[docs] Generate external links from mdx #1071

Merged
merged 3 commits into from
Dec 13, 2024
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
8 changes: 2 additions & 6 deletions docs/src/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react';
import { Link } from 'docs/src/components/Link';
import { ArrowRightIcon } from 'docs/src/components/icons/ArrowRightIcon';
import { Logo } from 'docs/src/components/Logo';
import { ExternalLinkIcon } from 'docs/src/components/icons/ExternalLinkIcon';
import RootLayout from './(public)/layout';
import './not-found.css';

Expand All @@ -25,11 +24,8 @@ export default function NotFound() {
Documentation <ArrowRightIcon />
</Link>

<Link
className="-m-1 inline-flex items-center gap-1 p-1"
href="http://github.com/mui/base-ui"
>
GitHub <ExternalLinkIcon />
<Link className="-m-1 p-1" href="http://github.com/mui/base-ui">
GitHub
</Link>
</div>
</div>
Expand Down
20 changes: 17 additions & 3 deletions docs/src/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import * as React from 'react';
import NextLink from 'next/link';
import clsx from 'clsx';
import NextLink from 'next/link';
import { ExternalLinkIcon } from 'docs/src/components/icons/ExternalLinkIcon';

export function Link({ className, ...props }: React.ComponentProps<typeof NextLink>) {
return <NextLink className={clsx('Link', className)} {...props} />;
export function Link(props: React.ComponentProps<typeof NextLink>) {
if (typeof props.href === 'string' && props.href.startsWith('http')) {
return (
<NextLink
target="_blank"
rel="noopener"
{...props}
className={clsx('Link inline-flex items-center gap-1', props.className)}
>
{props.children}
<ExternalLinkIcon />
</NextLink>
);
}
return <NextLink {...props} className={clsx('Link', props.className)} />;
}
Loading