feat: additional album release details
This commit is contained in:
parent
eb6b227006
commit
6e5bada890
5 changed files with 49 additions and 55 deletions
|
@ -26,32 +26,6 @@ export default async (request) => {
|
|||
const artistKey = sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()
|
||||
const albumKey = `${artistKey}-${sanitizeMediaString(album).replace(/\s+/g, '-').toLowerCase()}`
|
||||
|
||||
const { data: albumData, error: albumError } = await supabase
|
||||
.from('albums')
|
||||
.select('*')
|
||||
.eq('key', albumKey)
|
||||
.single()
|
||||
|
||||
if (albumError && albumError.code === 'PGRST116') {
|
||||
const { error: insertAlbumError } = await supabase.from('albums').insert([
|
||||
{
|
||||
mbid: null,
|
||||
image: `https://coryd.dev/media/albums/${albumKey}.jpg`,
|
||||
key: albumKey,
|
||||
name: album,
|
||||
tentative: true
|
||||
}
|
||||
])
|
||||
|
||||
if (insertAlbumError) {
|
||||
console.error('Error inserting album into Supabase:', insertAlbumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: insertAlbumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
} else if (albumError) {
|
||||
console.error('Error querying album from Supabase:', albumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: albumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { data: artistData, error: artistError } = await supabase
|
||||
.from('artists')
|
||||
.select('*')
|
||||
|
@ -78,6 +52,32 @@ export default async (request) => {
|
|||
return new Response(JSON.stringify({ status: 'error', message: artistError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { data: albumData, error: albumError } = await supabase
|
||||
.from('albums')
|
||||
.select('*')
|
||||
.eq('key', albumKey)
|
||||
.single()
|
||||
|
||||
if (albumError && albumError.code === 'PGRST116') {
|
||||
const { error: insertAlbumError } = await supabase.from('albums').insert([
|
||||
{
|
||||
mbid: null,
|
||||
image: `https://coryd.dev/media/albums/${albumKey}.jpg`,
|
||||
key: albumKey,
|
||||
name: album,
|
||||
tentative: true
|
||||
}
|
||||
])
|
||||
|
||||
if (insertAlbumError) {
|
||||
console.error('Error inserting album into Supabase:', insertAlbumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: insertAlbumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
} else if (albumError) {
|
||||
console.error('Error querying album from Supabase:', albumError.message)
|
||||
return new Response(JSON.stringify({ status: 'error', message: albumError.message }), { headers: { "Content-Type": "application/json" } })
|
||||
}
|
||||
|
||||
const { error: listenError } = await supabase.from('listens').insert([
|
||||
{
|
||||
artist_name: artist,
|
||||
|
|
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "14.2.0",
|
||||
"version": "14.3.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "14.2.0",
|
||||
"version": "14.3.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cdransf/api-text": "^1.2.2",
|
||||
|
@ -31,7 +31,7 @@
|
|||
"dotenv-flow": "^4.1.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
"liquidjs": "^10.12.0",
|
||||
"liquidjs": "^10.13.0",
|
||||
"luxon": "^3.4.4",
|
||||
"markdown-it": "^14.1.0",
|
||||
"markdown-it-anchor": "^8.6.7",
|
||||
|
@ -3640,9 +3640,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.4.763",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.763.tgz",
|
||||
"integrity": "sha512-k4J8NrtJ9QrvHLRo8Q18OncqBCB7tIUyqxRcJnlonQ0ioHKYB988GcDFF3ZePmnb8eHEopDs/wPHR/iGAFgoUQ==",
|
||||
"version": "1.4.764",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.764.tgz",
|
||||
"integrity": "sha512-ZXbPV46Y4dNCA+k7YHB+BYlzcoMtZ1yH6V0tQ1ul0wmA7RiwJfS29LSdRlE1myWBXRzEgm/Lz6tryj5WVQiLmg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/encodeurl": {
|
||||
|
@ -4778,9 +4778,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/liquidjs": {
|
||||
"version": "10.12.0",
|
||||
"resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-10.12.0.tgz",
|
||||
"integrity": "sha512-ZpT27WEqUu8IeddXoLbdeBTbRfV5r7oUKDjJMthuQKQTScgI8pbLGbSWiiAktQVpPG7mHMGsJ0JVbZYn1w9Gtg==",
|
||||
"version": "10.13.0",
|
||||
"resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-10.13.0.tgz",
|
||||
"integrity": "sha512-MnxinZZgtLcbuvwjCuNwsVthDQgcGEJzXRZZIq9rkUILwLbez3286Gsl0P3h9cL3crng45Joh+sCMcoQ0WsL5w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"commander": "^10.0.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "14.2.0",
|
||||
"version": "14.3.0",
|
||||
"description": "The source for my personal site. Built using 11ty.",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
@ -43,7 +43,7 @@
|
|||
"dotenv-flow": "^4.1.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
"liquidjs": "^10.12.0",
|
||||
"liquidjs": "^10.13.0",
|
||||
"luxon": "^3.4.4",
|
||||
"markdown-it": "^14.1.0",
|
||||
"markdown-it-anchor": "^8.6.7",
|
||||
|
|
|
@ -5,20 +5,6 @@ const SUPABASE_URL = process.env.SUPABASE_URL
|
|||
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||
|
||||
const deriveArtistName = (albumName, key) => {
|
||||
const normalizedAlbumName = albumName.toLowerCase().replace(/[\s.]+/g, '-').replace(/[^a-z0-9-]/g, '')
|
||||
if (key.endsWith(normalizedAlbumName)) {
|
||||
const artistName = key.slice(0, key.length - normalizedAlbumName.length).replace(/-$/, '')
|
||||
const formattedArtistName = artistName
|
||||
.split('-')
|
||||
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
||||
.join(' ')
|
||||
return formattedArtistName
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export default async function () {
|
||||
const today = DateTime.utc().toISO()
|
||||
const { data, error } = await supabase
|
||||
|
@ -28,7 +14,8 @@ export default async function () {
|
|||
key,
|
||||
image,
|
||||
release_date,
|
||||
release_link
|
||||
release_link,
|
||||
artists (name_string, genre, mbid)
|
||||
`)
|
||||
.gt('release_date', today)
|
||||
|
||||
|
@ -39,10 +26,12 @@ export default async function () {
|
|||
|
||||
return data.map(album => {
|
||||
return {
|
||||
artist: deriveArtistName(album['name'], album['key']),
|
||||
artist: album['artists']['name_string'],
|
||||
title: album['name'],
|
||||
date: DateTime.fromISO(album['release_date']).toLocaleString(DateTime.DATE_FULL),
|
||||
url: album['release_link']
|
||||
url: album['release_link'],
|
||||
genre: album['artists']['genre'],
|
||||
mbid: album['artists']['mbid'],
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,8 +8,13 @@
|
|||
<li>
|
||||
<strong>{{ album.date }}: </strong>
|
||||
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
|
||||
{{ album.title }} by {{ album.artist }}
|
||||
{{ album.title }}
|
||||
</a>
|
||||
<span> by </span>
|
||||
<a href="https://musicbrainz.org/artist/{{ album.mbid }}">
|
||||
{{ album.artist }}
|
||||
</a>
|
||||
<span> • {{ album.genre }}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Reference in a new issue