diff --git a/website/src/components/VideoContent.jsx b/website/src/components/VideoContent.jsx index 3e6e6b0d40..be2210eb10 100644 --- a/website/src/components/VideoContent.jsx +++ b/website/src/components/VideoContent.jsx @@ -1,29 +1,98 @@ // biome-ignore lint/correctness/noUnusedImports: Needs this for React to work -import React from 'react'; +import React, { useState, useCallback } from 'react'; import Admonition from '@theme/Admonition'; +import styles from './VideoContent.module.css'; + +// Extract YouTube video ID from various URL formats +const extractVideoId = (url) => { + const regex = + /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/; + const match = url.match(regex); + return match ? match[1] : null; +}; + +// Lazy video component that shows thumbnail until clicked +const LazyVideo = ({ url, title = 'YouTube video player' }) => { + const [isLoaded, setIsLoaded] = useState(false); + const videoId = extractVideoId(url); + + const handleLoad = useCallback(() => { + setIsLoaded(true); + }, []); + + if (!videoId) { + return ( + Invalid YouTube URL: {url} + ); + } + + if (!isLoaded) { + return ( +
e.key === 'Enter' && handleLoad()} + role='button' + tabIndex={0} + style={{ + backgroundImage: `url(https://img.youtube.com/vi/${videoId}/maxresdefault.jpg)`, + }} + aria-label={`Load ${title}`} + > + {/* Play button overlay */} +
+ + + +
+ + {/* Loading hint */} +
Click to load video
+
+ ); + } -const Component = ({ videoUrls }) => { return ( -
- {videoUrls ? ( - videoUrls.map((url) => ( -