Skip to content

Commit c42aa8c

Browse files
committed
feat: youtube link render
Signed-off-by: Innei <[email protected]>
1 parent 0215f38 commit c42aa8c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/components/ui/markdown/renderers/LinkRenderer.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ export const LinkRenderer = ({ href }: { href: string }) => {
2828
const [_, owner, repo] = url.pathname.split('/')
2929
return <LinkCard id={`${owner}/${repo}`} source="gh" />
3030
}
31+
32+
case isYoutubeUrl(url): {
33+
const id = url.searchParams.get('v')!
34+
return (
35+
<div className="relative h-0 w-full pb-[56%]">
36+
<iframe
37+
src={`https://www.youtube.com/embed/${id}`}
38+
className="absolute inset-0 h-full w-full border-0"
39+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
40+
allowFullScreen
41+
title="YouTube video player"
42+
/>
43+
</div>
44+
)
45+
}
3146
}
3247
}
3348
// fallback to default renderer
@@ -53,3 +68,7 @@ const isGithubRepoUrl = (url: URL) => {
5368
url.pathname.split('/').length === 3
5469
)
5570
}
71+
72+
const isYoutubeUrl = (url: URL) => {
73+
return url.hostname === 'www.youtube.com' && url.pathname.startsWith('/watch')
74+
}

0 commit comments

Comments
 (0)