-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
267 lines (251 loc) · 7.65 KB
/
index.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Songstr</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"
/>
<style>
.disabled {
pointer-events: none; /* Makes the element non-clickable */
opacity: 0.5; /* Makes the element semi-transparent */
}
body {
font-family: 'Arial', sans-serif;
padding: 50px;
background-color: #ececec;
}
.container {
max-width: 500px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 15px;
box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.1);
}
.media-content {
display: flex;
align-items: center;
margin-bottom: 30px;
border-bottom: 2px solid #f1f1f1;
padding-bottom: 20px;
}
.media-content img {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
margin-right: 20px;
}
.listen,
.buy,
.customize {
margin-bottom: 30px;
}
.listen a,
.buy a {
display: inline-block;
background-color: #333;
padding: 10px 20px;
margin-right: 10px;
border-radius: 5px;
text-decoration: none;
color: #fff;
transition: background-color 0.3s ease;
}
.listen a:hover,
.buy a:hover {
background-color: #555;
}
.customize ul {
list-style-type: none;
padding: 0;
}
.customize ul li {
padding: 5px 0;
display: flex;
align-items: center;
}
.customize ul li i {
margin-right: 10px;
color: #ff5252;
}
button {
background-color: #ff5252;
border: none;
padding: 10px 20px;
color: #fff;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-right: 10px;
}
button:hover {
background-color: #ff7676;
}
.youtube-embed {
position: relative;
padding-bottom: 56.25%; /* Aspect ratio */
padding-top: 30px;
height: 0;
overflow: hidden;
}
.youtube-embed iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<script type="application/ld+json" id="songData">
{
"@context": "http://schema.org/",
"@type": "MusicRecording",
"name": "Don't You Worry 'Bout a Thing",
"byArtist": {
"@type": "MusicGroup",
"name": "Weldon Irvine"
},
"image": "https://i.discogs.com/ea8f4YmlAq52n54uYFfLmcWXlATJCCRoNnNXoHemHxo/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTE0MTI1/NTU3LTE1NjgzMTQ5/NjktNDExOS5qcGVn.jpeg",
"url": {
"YouTube": "https://www.youtube.com/watch?v=yEemGgYb2Io",
"AppleMusic": "#",
"iTunes": "#",
"Amazon": "#"
}
}
</script>
<script type="module">
import { html, render } from './js/standalone.module.js'
async function fetchSongData() {
const params = new URLSearchParams(window.location.search)
const dataURL = params.get('uri')
console.log(dataURL)
if (dataURL) {
try {
const response = await fetch(dataURL)
if (response.ok) {
let data = await response.json()
console.log(data)
return data
}
} catch (err) {
console.warn(
'Failed to fetch from provided URL, falling back to data island.',
err
)
}
}
const songDataEl = document.getElementById('songData')
return JSON.parse(songDataEl.textContent)
}
// Style
const styles = `
body {
font-family: 'Arial', sans-serif;
padding: 50px;
background-color: #ececec;
}
`
function getYouTubeVideoID(url) {
const regex = /(?:v=)([a-zA-Z0-9_-]{11})/
const match = url.match(regex)
return match ? match[1] : null
}
function YouTubeEmbed(props) {
const videoID = getYouTubeVideoID(props.url)
if (!videoID) return null
return html`
<div class="youtube-embed">
<iframe
width="480"
height="270"
src="https://www.youtube.com/embed/${videoID}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
`
}
// Songstr Component
function Songstr(props) {
// Get data from structured data island
// const songDataEl = document.getElementById('songData')
// const songData = JSON.parse(songDataEl.textContent)
const songData = props.songData
const videoID = getYouTubeVideoID(songData.url.YouTube)
console.log(songData)
console.log('videoID', videoID)
return html`
<style>
${styles}
</style>
<div class="container">
<div class="media-content">
<img src="${songData.image}" alt="Song Album Art" />
<div>
<h2>${songData.name}</h2>
<p>${songData.byArtist.name}</p>
</div>
</div>
<${YouTubeEmbed} url=${songData.url.YouTube} />
<div class="listen">
<h3>Listen on</h3>
<a href="${songData.url.YouTube}"
><i class="fab fa-youtube"></i> YouTube</a
>
<a href="${songData.url.AppleMusic}" class="disabled"
><i class="fab fa-apple"></i> Apple Music</a
>
</div>
<div class="buy">
<div class="buy">
<h3>Buy on</h3>
<a href="${songData.url.Tidal}" class="disabled">
<img
src="./images/tidal.png"
alt="Tidal"
style="width: 16px; height: 16px; filter: invert(100%);"
/>${' '} Tidal
</a>
<a href="${songData.url.Amazon}" class="disabled">
<i class="fab fa-amazon"></i> Amazon
</a>
</div>
</div>
<div class="customize">
<h3>Edit and customize this page</h3>
<ul>
<li>
<i class="fas fa-ticket-alt"></i>Add links for tickets, merch
or anything
</li>
<li>
<i class="fas fa-link"></i>Customize the URL using domains
</li>
<li>
<i class="fas fa-sync-alt"></i>Easily update all streaming
links with each new release
</li>
</ul>
<button class="disabled">Customize</button>
<button class="disabled">Create new</button>
</div>
</div>
`
}
// Render the Songstr component when the document is ready
window.addEventListener('DOMContentLoaded', async () => {
const songData = await fetchSongData()
console.log(songData)
render(html`<${Songstr} songData=${songData} />`, document.body)
})
</script>
</head>
<body></body>
</html>