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

fix: blog link component #80

Merged
merged 2 commits into from
Oct 24, 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
27 changes: 27 additions & 0 deletions components/blog/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use client';
import { cn } from '@/lib/utils';
import React, { HTMLAttributes, PropsWithChildren } from 'react';

function Link({
children,
...props
}: PropsWithChildren<HTMLAttributes<HTMLAnchorElement>> & {
children: React.ReactNode;
}) {
return (
<span
onClick={() => {
if ('href' in props) {
const href = props.href as string;
window.open(href, '_blank');
}
}}
className={cn('decoration-muted cursor-pointer text-black underline opacity-70 hover:opacity-100')}
rel='noopener noreferrer'
>
{children}
</span>
);
}

export default Link;
18 changes: 3 additions & 15 deletions components/blog/mdx-render.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import CodeBlock from '@/components/blog/code-block';
import InlineCodeTag from '@/components/blog/inline-code';
import Link from '@/components/blog/link';
import Quote from '@/components/blog/quote';
import Caption from '@/components/blog/caption';
import Video from '@/components/blog/video';
import { cn } from '@/lib/utils';
import { MDXRemote } from 'next-mdx-remote/rsc';
import Image, { ImageProps } from './mdx-image';
import { HTMLAttributes, PropsWithChildren } from 'react';
import { HTMLAttributes } from 'react';
import Admonition from './admonition';
import Heading, { HeadingProps } from './heading';
import MDXTable from './mdx-table';
Expand Down Expand Up @@ -55,20 +56,7 @@ const components = {
/>
),
Video,
a: (props: PropsWithChildren<HTMLAttributes<HTMLAnchorElement>>) => {
const { children, ...rest } = props;

return (
<a
{...rest}
className={cn('decoration-muted text-black opacity-70 hover:opacity-100')}
target='_blank'
rel='noopener noreferrer'
>
{children}
</a>
);
},
a: Link,
};

const MyMDXRender: React.FC<MyMDXComponentProps> = ({ source }) => {
Expand Down
Loading