-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #985 from nature-of-code/dev/video-link
[Feature] Incorporate video link with headings
- Loading branch information
Showing
10 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { FaYoutube, FaPlay } from 'react-icons/fa'; | ||
|
||
function getVideoIdFromYoutubeUrl(url) { | ||
try { | ||
const parsedUrl = new URL(url); | ||
if ( | ||
parsedUrl.hostname === 'www.youtube.com' || | ||
parsedUrl.hostname === 'youtube.com' | ||
) { | ||
return parsedUrl.searchParams.get('v'); | ||
} else if (parsedUrl.hostname === 'youtu.be') { | ||
return parsedUrl.pathname.slice(1); | ||
} | ||
return null; | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
const VideoLink = (props) => { | ||
const videoId = getVideoIdFromYoutubeUrl(props['href']); | ||
|
||
return ( | ||
<div className="inline-block"> | ||
<a | ||
className="group relative flex items-center gap-2 text-base text-noc-400 no-underline" | ||
href={props['href']} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
<FaYoutube /> | ||
{props['data-title']} | ||
|
||
{videoId && ( | ||
<div className="not-prose absolute top-0 hidden w-80 pt-10 group-hover:block"> | ||
<div className="relative rounded-lg bg-noc-400 bg-opacity-50 p-4"> | ||
<div className="flex aspect-video items-center overflow-hidden rounded object-cover"> | ||
<picture> | ||
<source | ||
type="image/webp" | ||
srcSet={`https://img.youtube.com/vi_webp/${videoId}/sddefault.webp`} | ||
/> | ||
<source | ||
type="image/jpeg" | ||
srcSet={`https://i.ytimg.com/vi/${videoId}/sddefault.jpg`} | ||
/> | ||
<img | ||
src={`https://i.ytimg.com/vi/${videoId}/sddefault.jpg`} | ||
alt="youtube video thumbnail" | ||
/> | ||
</picture> | ||
</div> | ||
|
||
<FaPlay className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 text-4xl text-noc-400" /> | ||
</div> | ||
</div> | ||
)} | ||
</a> | ||
</div> | ||
); | ||
}; | ||
|
||
export default VideoLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters