your personal website on atproto - mirror blento.app
at next 68 lines 2.2 kB view raw
1import type { CardDefinition } from '../types'; 2import CreateSpotifyCardModal from './CreateSpotifyCardModal.svelte'; 3import SpotifyCard from './SpotifyCard.svelte'; 4 5const cardType = 'spotify-list-embed'; 6 7export const SpotifyCardDefinition = { 8 type: cardType, 9 contentComponent: SpotifyCard, 10 creationModalComponent: CreateSpotifyCardModal, 11 createNew: (item) => { 12 item.cardType = cardType; 13 item.cardData = {}; 14 item.w = 4; 15 item.mobileW = 8; 16 item.h = 5; 17 item.mobileH = 10; 18 }, 19 20 onUrlHandler: (url, item) => { 21 const match = matchSpotifyUrl(url); 22 if (!match) return null; 23 24 item.cardData.spotifyType = match.type; 25 item.cardData.spotifyId = match.id; 26 item.cardData.href = url; 27 28 item.w = 4; 29 item.mobileW = 8; 30 item.h = 5; 31 item.mobileH = 10; 32 33 return item; 34 }, 35 36 urlHandlerPriority: 2, 37 38 name: 'Spotify Embed', 39 canResize: true, 40 minW: 4, 41 minH: 5, 42 43 keywords: ['music', 'song', 'playlist', 'album', 'podcast'], 44 groups: ['Media'], 45 icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-4"><path d="M12 0C5.4 0 0 5.4 0 12s5.4 12 12 12 12-5.4 12-12S18.66 0 12 0zm5.521 17.34c-.24.359-.66.48-1.021.24-2.82-1.74-6.36-2.101-10.561-1.141-.418.122-.779-.179-.899-.539-.12-.421.18-.78.54-.9 4.56-1.021 8.52-.6 11.64 1.32.42.18.479.659.301 1.02zm1.44-3.3c-.301.42-.841.6-1.262.3-3.239-1.98-8.159-2.58-11.939-1.38-.479.12-1.02-.12-1.14-.6-.12-.48.12-1.021.6-1.141C9.6 9.9 15 10.561 18.72 12.84c.361.181.54.78.241 1.2zm.12-3.36C15.24 8.4 8.82 8.16 5.16 9.301c-.6.179-1.2-.181-1.38-.721-.18-.601.18-1.2.72-1.381 4.26-1.26 11.28-1.02 15.721 1.621.539.3.719 1.02.419 1.56-.299.421-1.02.599-1.559.3z" /></svg>` 46} as CardDefinition & { type: typeof cardType }; 47 48// Match Spotify album and playlist URLs 49// Examples: 50// https://open.spotify.com/album/1DFixLWuPkv3KT3TnV35m3 51// https://open.spotify.com/playlist/37i9dQZF1DXcBWIGoYBM5M 52function matchSpotifyUrl( 53 url: string | undefined 54): { type: 'album' | 'playlist'; id: string } | null { 55 if (!url) return null; 56 57 const pattern = /open\.spotify\.com\/(album|playlist)\/([a-zA-Z0-9]+)/; 58 const match = url.match(pattern); 59 60 if (match) { 61 return { 62 type: match[1] as 'album' | 'playlist', 63 id: match[2] 64 }; 65 } 66 67 return null; 68}