Add Apple Music embed
This commit is contained in:
parent
37ef874dc6
commit
68b5d9efcb
@ -8,7 +8,7 @@
|
||||
<meta name="description" content="Fast nostr web ui" />
|
||||
<meta
|
||||
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; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* ws://*:* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' 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; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; connect-src wss://* ws://*:* 'self' https://*; img-src * data:; font-src https://fonts.gstatic.com; media-src *; script-src 'self' 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.gstatic.com" crossorigin />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
||||
|
@ -146,3 +146,9 @@ export const SpotifyRegex = /open\.spotify\.com\/(track|album|playlist|episode)\
|
||||
* Twitch embed regex
|
||||
*/
|
||||
export const TwitchRegex = /twitch.tv\/([a-z0-9_]+$)/i;
|
||||
|
||||
/**
|
||||
* Apple Music embed regex
|
||||
*/
|
||||
export const AppleMusicRegex =
|
||||
/music\.apple\.com\/([a-z]{2}\/)?(?:album|playlist)\/[\w\d-]+\/([.a-zA-Z0-9-]+)(?:\?i=\d+)?/i;
|
||||
|
16
src/Element/AppleMusicEmbed.tsx
Normal file
16
src/Element/AppleMusicEmbed.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
const AppleMusicEmbed = ({ link }: { link: string }) => {
|
||||
const convertedUrl = link.replace("music.apple.com", "embed.music.apple.com");
|
||||
const isSongLink = /\?i=\d+$/.test(convertedUrl);
|
||||
|
||||
return (
|
||||
<iframe
|
||||
allow="autoplay *; encrypted-media *; fullscreen *; clipboard-write"
|
||||
frameBorder="0"
|
||||
height={isSongLink ? 175 : 450}
|
||||
style={{ width: "100%", maxWidth: 660, overflow: "hidden", background: "transparent" }}
|
||||
sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation"
|
||||
src={convertedUrl}></iframe>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppleMusicEmbed;
|
@ -11,6 +11,7 @@ import {
|
||||
MixCloudRegex,
|
||||
SpotifyRegex,
|
||||
TwitchRegex,
|
||||
AppleMusicRegex,
|
||||
} from "Const";
|
||||
import { RootState } from "State/Store";
|
||||
import SoundCloudEmbed from "Element/SoundCloudEmded";
|
||||
@ -20,6 +21,7 @@ import TidalEmbed from "Element/TidalEmbed";
|
||||
import { ProxyImg } from "Element/ProxyImg";
|
||||
import { HexKey } from "Nostr";
|
||||
import TwitchEmbed from "./TwitchEmbed";
|
||||
import AppleMusicEmbed from "./AppleMusicEmbed";
|
||||
|
||||
export default function HyperText({ link, creator }: { link: string; creator: HexKey }) {
|
||||
const pref = useSelector((s: RootState) => s.login.preferences);
|
||||
@ -46,8 +48,9 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
||||
const mixcloudId = MixCloudRegex.test(a) && RegExp.$1;
|
||||
const spotifyId = SpotifyRegex.test(a);
|
||||
const twitchId = TwitchRegex.test(a);
|
||||
const appleMusicId = AppleMusicRegex.test(a);
|
||||
const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1;
|
||||
if (extension) {
|
||||
if (extension && !appleMusicId) {
|
||||
switch (extension) {
|
||||
case "gif":
|
||||
case "jpg":
|
||||
@ -114,6 +117,8 @@ export default function HyperText({ link, creator }: { link: string; creator: He
|
||||
return <SpotifyEmbed link={a} />;
|
||||
} else if (twitchId) {
|
||||
return <TwitchEmbed link={a} />;
|
||||
} else if (appleMusicId) {
|
||||
return <AppleMusicEmbed link={a} />;
|
||||
} else {
|
||||
return (
|
||||
<a href={a} onClick={e => e.stopPropagation()} target="_blank" rel="noreferrer" className="ext">
|
||||
|
Loading…
x
Reference in New Issue
Block a user