add Nostr Nests embed #377
@ -8,7 +8,7 @@
|
|||||||
<meta name="description" content="Fast nostr web ui" />
|
<meta name="description" content="Fast nostr web ui" />
|
||||||
<meta
|
<meta
|
||||||
http-equiv="Content-Security-Policy"
|
http-equiv="Content-Security-Policy"
|
||||||
content="default-src 'self'; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv https://embed.music.apple.com'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src *; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' 'wasm-unsafe-eval' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;" />
|
content="default-src 'self'; child-src 'none'; worker-src 'self'; frame-src youtube.com www.youtube.com https://platform.twitter.com https://embed.tidal.com https://w.soundcloud.com https://www.mixcloud.com https://open.spotify.com https://player.twitch.tv https://embed.music.apple.com https://nostrnests.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src *; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' 'wasm-unsafe-eval' https://static.cloudflareinsights.com https://platform.twitter.com https://embed.tidal.com;" />
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
||||||
|
@ -147,3 +147,8 @@ export const TwitchRegex = /twitch.tv\/([a-z0-9_]+$)/i;
|
|||||||
*/
|
*/
|
||||||
export const AppleMusicRegex =
|
export const AppleMusicRegex =
|
||||||
/music\.apple\.com\/([a-z]{2}\/)?(?:album|playlist)\/[\w\d-]+\/([.a-zA-Z0-9-]+)(?:\?i=\d+)?/i;
|
/music\.apple\.com\/([a-z]{2}\/)?(?:album|playlist)\/[\w\d-]+\/([.a-zA-Z0-9-]+)(?:\?i=\d+)?/i;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nostr Nests embed regex
|
||||||
|
*/
|
||||||
|
export const NostrNestsRegex = /nostrnests\.com\/[a-zA-Z0-9]+/i;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState, Children } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { TwitterTweetEmbed } from "react-twitter-embed";
|
import { TwitterTweetEmbed } from "react-twitter-embed";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
@ -14,6 +14,7 @@ import {
|
|||||||
SpotifyRegex,
|
SpotifyRegex,
|
||||||
TwitchRegex,
|
TwitchRegex,
|
||||||
AppleMusicRegex,
|
AppleMusicRegex,
|
||||||
|
NostrNestsRegex,
|
||||||
} from "Const";
|
} from "Const";
|
||||||
import { RootState } from "State/Store";
|
import { RootState } from "State/Store";
|
||||||
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
||||||
@ -23,6 +24,7 @@ import TidalEmbed from "Element/TidalEmbed";
|
|||||||
import { ProxyImg } from "Element/ProxyImg";
|
import { ProxyImg } from "Element/ProxyImg";
|
||||||
import TwitchEmbed from "Element/TwitchEmbed";
|
import TwitchEmbed from "Element/TwitchEmbed";
|
||||||
import AppleMusicEmbed from "Element/AppleMusicEmbed";
|
import AppleMusicEmbed from "Element/AppleMusicEmbed";
|
||||||
|
import NostrNestsEmbed from "Element/NostrNestsEmbed";
|
||||||
|
|
||||||
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
|
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
|
||||||
const pref = useSelector((s: RootState) => s.login.preferences);
|
const pref = useSelector((s: RootState) => s.login.preferences);
|
||||||
@ -67,6 +69,7 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
|||||||
const isSpotifyLink = SpotifyRegex.test(a);
|
const isSpotifyLink = SpotifyRegex.test(a);
|
||||||
const isTwitchLink = TwitchRegex.test(a);
|
const isTwitchLink = TwitchRegex.test(a);
|
||||||
const isAppleMusicLink = AppleMusicRegex.test(a);
|
const isAppleMusicLink = AppleMusicRegex.test(a);
|
||||||
|
const isNostrNestsLink = NostrNestsRegex.test(a);
|
||||||
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
||||||
if (extension && !isAppleMusicLink) {
|
if (extension && !isAppleMusicLink) {
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
@ -133,6 +136,13 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
|||||||
return <TwitchEmbed link={a} />;
|
return <TwitchEmbed link={a} />;
|
||||||
} else if (isAppleMusicLink) {
|
} else if (isAppleMusicLink) {
|
||||||
return <AppleMusicEmbed link={a} />;
|
return <AppleMusicEmbed link={a} />;
|
||||||
|
} else if (isNostrNestsLink) {
|
||||||
|
return [
|
||||||
|
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
||||||
|
{a}
|
||||||
|
</a>,
|
||||||
|
<NostrNestsEmbed link={a} />,
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
||||||
@ -150,9 +160,6 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
|||||||
);
|
);
|
||||||
}, [link, reveal]);
|
}, [link, reveal]);
|
||||||
|
|
||||||
const elm = render();
|
const children = render();
|
||||||
if (elm.type !== "a") {
|
return <>{Children.map(children, elm => (elm.type === "a" ? elm : wrapReveal(elm, link)))}</>;
|
||||||
return wrapReveal(elm, link);
|
|
||||||
}
|
|
||||||
return elm;
|
|
||||||
}
|
}
|
||||||
|
5
packages/app/src/Element/NostrNestsEmbed.tsx
Normal file
5
packages/app/src/Element/NostrNestsEmbed.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const NostrNestsEmbed = ({ link }: { link: string }) => (
|
||||||
|
<iframe src={link} allow="microphone" width="480" height="680" style={{ maxHeight: 680 }}></iframe>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default NostrNestsEmbed;
|
Loading…
Reference in New Issue
Block a user