feat: embed youtube videos
This commit is contained in:
parent
921122bd89
commit
9dfbb52768
@ -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" />
|
||||
|
16
src/Text.js
16
src/Text.js
@ -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>
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user