feat: embed youtube videos

This commit is contained in:
Alejandro Gomez 2023-01-06 18:00:33 +01:00
parent 921122bd89
commit 9dfbb52768
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
2 changed files with 15 additions and 3 deletions

View File

@ -8,7 +8,7 @@
<meta name="theme-color" content="#000000" />
<meta name="description" content="Fast nostr web ui" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; child-src 'none'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com;" />
content="default-src 'self'; child-src 'none'; frame-src youtube.com www.youtube.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' https://static.cloudflareinsights.com;" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/nostrich_512.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

View File

@ -10,8 +10,10 @@ export function extractLinks(fragments) {
return f.split(UrlRegex).map(a => {
if (a.startsWith("http")) {
try {
let url = new URL(a);
let ext = url.pathname.toLowerCase().match(FileExtensionRegex);
const url = new URL(a);
const vParam = url.searchParams.get('v')
const isYoutube = (url.host === "www.youtube.com" || url.host === "youtube.com" ) && vParam
const ext = url.pathname.toLowerCase().match(FileExtensionRegex);
if (ext) {
switch (ext[1]) {
case "gif":
@ -30,6 +32,16 @@ export function extractLinks(fragments) {
return <video key={url} src={url} controls />
}
}
} else if (isYoutube) {
return (
<iframe
src={`https://www.youtube.com/embed/${vParam}`}
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen=""
/>
)
} else {
return <a key={url} href={url}>{url.toString()}</a>
}