-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathyoutube.tsx
More file actions
43 lines (40 loc) · 1.04 KB
/
youtube.tsx
File metadata and controls
43 lines (40 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Image from "next/image";
import { youtubeParser } from "@/lib/utils";
import CoverImage from "@/components/cover-image";
import { YouTubeEmbed } from "./youtube-embed";
export function YouTube(props: {
youtube: string;
image?: any;
className?: string;
}) {
const { youtube, image, className } = props;
if (!youtube) {
return <></>;
}
const id = youtubeParser(youtube);
return (
<YouTubeEmbed youtube={youtube}>
{image?.asset?._ref ? (
<CoverImage image={image} priority={true} className={className} />
) : (
<picture>
<source
type="image/webp"
srcSet={[
`https://i.ytimg.com/vi_webp/${id}/mqdefault.webp 320w`,
`https://i.ytimg.com/vi_webp/${id}/hqdefault.webp 480w`,
`https://i.ytimg.com/vi_webp/${id}/sddefault.webp 640w`,
].join(", ")}
/>
<Image
style={{ width: "100%", height: "100%", objectFit: "cover" }}
src={`https://i.ytimg.com/vi/${id}/sddefault.jpg`}
alt=""
width={640}
height={480}
/>
</picture>
)}
</YouTubeEmbed>
);
}