-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathSpotify.astro
More file actions
31 lines (27 loc) · 839 Bytes
/
Copy pathSpotify.astro
File metadata and controls
31 lines (27 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
export interface Props {
id: string;
dark?: boolean;
compact?: boolean;
widthPercent?: number;
}
const { id, dark = false, compact = false, widthPercent = 100 } = Astro.props;
// values based on Spotify embed generator
const height = compact ? 152 : 352;
const theme = dark ? 0 : 1;
const { pathname } = new URL(id);
let [type, ...params] = pathname.split('/').filter(Boolean);
type = type === 'user' ? 'playlist' : type;
const playlistId = params.slice(-1);
const embedUrl = `https://open.spotify.com/embed/${type}/${playlistId}?theme=${theme}`;
---
<iframe
title=`Spotify ${type} Embed`
style="border-radius:12px"
src={embedUrl}
width=`${widthPercent}%`
height=`${height}`
frameBorder="0"
allowfullscreen=""
allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
loading="lazy"></iframe>