add Nostr Nests embed (#377)

* add Nostr Nests embed

* remove wildcard

* fix import to match import convention

* always show link, but hide iframe when necessary
This commit is contained in:
Sam Samskies
2023-03-03 09:05:10 -10:00
committed by GitHub
parent ca9b8a9e72
commit 4325c49435
4 changed files with 24 additions and 7 deletions

View File

@ -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;

View File

@ -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 <TwitchEmbed link={a} />;
} else if (isAppleMusicLink) {
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 {
return (
<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]);
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)))}</>;
}

View 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;