diff --git a/packages/app/public/index.html b/packages/app/public/index.html index c45a433..931a259 100644 --- a/packages/app/public/index.html +++ b/packages/app/public/index.html @@ -8,7 +8,7 @@ + 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;" /> diff --git a/packages/app/src/Const.ts b/packages/app/src/Const.ts index e6b3ea2..7adbdf9 100644 --- a/packages/app/src/Const.ts +++ b/packages/app/src/Const.ts @@ -147,3 +147,8 @@ export const TwitchRegex = /twitch.tv\/([a-z0-9_]+$)/i; */ export const AppleMusicRegex = /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; diff --git a/packages/app/src/Element/HyperText.tsx b/packages/app/src/Element/HyperText.tsx index c03d18e..e411e1d 100644 --- a/packages/app/src/Element/HyperText.tsx +++ b/packages/app/src/Element/HyperText.tsx @@ -1,4 +1,4 @@ -import { useCallback, useState } from "react"; +import { useCallback, useState, Children } from "react"; import { useSelector } from "react-redux"; import { TwitterTweetEmbed } from "react-twitter-embed"; import { FormattedMessage } from "react-intl"; @@ -14,6 +14,7 @@ import { SpotifyRegex, TwitchRegex, AppleMusicRegex, + NostrNestsRegex, } from "Const"; import { RootState } from "State/Store"; import SoundCloudEmbed from "Element/SoundCloudEmded"; @@ -23,6 +24,7 @@ import TidalEmbed from "Element/TidalEmbed"; import { ProxyImg } from "Element/ProxyImg"; import TwitchEmbed from "Element/TwitchEmbed"; import AppleMusicEmbed from "Element/AppleMusicEmbed"; +import NostrNestsEmbed from "Element/NostrNestsEmbed"; export default function HyperText({ link, creator }: { link: string; creator: HexKey }) { 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 isTwitchLink = TwitchRegex.test(a); const isAppleMusicLink = AppleMusicRegex.test(a); + const isNostrNestsLink = NostrNestsRegex.test(a); const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1; if (extension && !isAppleMusicLink) { switch (extension) { @@ -133,6 +136,13 @@ export default function HyperText({ link, creator }: { link: string; creator: He return ; } else if (isAppleMusicLink) { return ; + } else if (isNostrNestsLink) { + return [ + e.stopPropagation()} target="_blank" rel="noreferrer" className="ext"> + {a} + , + , + ]; } else { return ( e.stopPropagation()} target="_blank" rel="noreferrer" className="ext"> @@ -150,9 +160,6 @@ export default function HyperText({ link, creator }: { link: string; creator: He ); }, [link, reveal]); - const elm = render(); - if (elm.type !== "a") { - return wrapReveal(elm, link); - } - return elm; + const children = render(); + return <>{Children.map(children, elm => (elm.type === "a" ? elm : wrapReveal(elm, link)))}; } diff --git a/packages/app/src/Element/NostrNestsEmbed.tsx b/packages/app/src/Element/NostrNestsEmbed.tsx new file mode 100644 index 0000000..339b802 --- /dev/null +++ b/packages/app/src/Element/NostrNestsEmbed.tsx @@ -0,0 +1,5 @@ +const NostrNestsEmbed = ({ link }: { link: string }) => ( + +); + +export default NostrNestsEmbed;