feat: additional album release details

This commit is contained in:
Cory Dransfeldt 2024-05-13 12:11:43 -07:00
parent eb6b227006
commit 6e5bada890
No known key found for this signature in database
5 changed files with 49 additions and 55 deletions

View file

@ -26,32 +26,6 @@ export default async (request) => {
const artistKey = sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase() const artistKey = sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()
const albumKey = `${artistKey}-${sanitizeMediaString(album).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 const { data: artistData, error: artistError } = await supabase
.from('artists') .from('artists')
.select('*') .select('*')
@ -78,6 +52,32 @@ export default async (request) => {
return new Response(JSON.stringify({ status: 'error', message: artistError.message }), { headers: { "Content-Type": "application/json" } }) 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([ const { error: listenError } = await supabase.from('listens').insert([
{ {
artist_name: artist, artist_name: artist,

18
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "14.2.0", "version": "14.3.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "coryd.dev", "name": "coryd.dev",
"version": "14.2.0", "version": "14.3.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@cdransf/api-text": "^1.2.2", "@cdransf/api-text": "^1.2.2",
@ -31,7 +31,7 @@
"dotenv-flow": "^4.1.0", "dotenv-flow": "^4.1.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"html-minifier-terser": "^7.2.0", "html-minifier-terser": "^7.2.0",
"liquidjs": "^10.12.0", "liquidjs": "^10.13.0",
"luxon": "^3.4.4", "luxon": "^3.4.4",
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"markdown-it-anchor": "^8.6.7", "markdown-it-anchor": "^8.6.7",
@ -3640,9 +3640,9 @@
"dev": true "dev": true
}, },
"node_modules/electron-to-chromium": { "node_modules/electron-to-chromium": {
"version": "1.4.763", "version": "1.4.764",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.763.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.764.tgz",
"integrity": "sha512-k4J8NrtJ9QrvHLRo8Q18OncqBCB7tIUyqxRcJnlonQ0ioHKYB988GcDFF3ZePmnb8eHEopDs/wPHR/iGAFgoUQ==", "integrity": "sha512-ZXbPV46Y4dNCA+k7YHB+BYlzcoMtZ1yH6V0tQ1ul0wmA7RiwJfS29LSdRlE1myWBXRzEgm/Lz6tryj5WVQiLmg==",
"dev": true "dev": true
}, },
"node_modules/encodeurl": { "node_modules/encodeurl": {
@ -4778,9 +4778,9 @@
} }
}, },
"node_modules/liquidjs": { "node_modules/liquidjs": {
"version": "10.12.0", "version": "10.13.0",
"resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-10.12.0.tgz", "resolved": "https://registry.npmjs.org/liquidjs/-/liquidjs-10.13.0.tgz",
"integrity": "sha512-ZpT27WEqUu8IeddXoLbdeBTbRfV5r7oUKDjJMthuQKQTScgI8pbLGbSWiiAktQVpPG7mHMGsJ0JVbZYn1w9Gtg==", "integrity": "sha512-MnxinZZgtLcbuvwjCuNwsVthDQgcGEJzXRZZIq9rkUILwLbez3286Gsl0P3h9cL3crng45Joh+sCMcoQ0WsL5w==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"commander": "^10.0.0" "commander": "^10.0.0"

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "14.2.0", "version": "14.3.0",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {
@ -43,7 +43,7 @@
"dotenv-flow": "^4.1.0", "dotenv-flow": "^4.1.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"html-minifier-terser": "^7.2.0", "html-minifier-terser": "^7.2.0",
"liquidjs": "^10.12.0", "liquidjs": "^10.13.0",
"luxon": "^3.4.4", "luxon": "^3.4.4",
"markdown-it": "^14.1.0", "markdown-it": "^14.1.0",
"markdown-it-anchor": "^8.6.7", "markdown-it-anchor": "^8.6.7",

View file

@ -5,20 +5,6 @@ const SUPABASE_URL = process.env.SUPABASE_URL
const SUPABASE_KEY = process.env.SUPABASE_KEY const SUPABASE_KEY = process.env.SUPABASE_KEY
const supabase = createClient(SUPABASE_URL, 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 () { export default async function () {
const today = DateTime.utc().toISO() const today = DateTime.utc().toISO()
const { data, error } = await supabase const { data, error } = await supabase
@ -28,7 +14,8 @@ export default async function () {
key, key,
image, image,
release_date, release_date,
release_link release_link,
artists (name_string, genre, mbid)
`) `)
.gt('release_date', today) .gt('release_date', today)
@ -39,10 +26,12 @@ export default async function () {
return data.map(album => { return data.map(album => {
return { return {
artist: deriveArtistName(album['name'], album['key']), artist: album['artists']['name_string'],
title: album['name'], title: album['name'],
date: DateTime.fromISO(album['release_date']).toLocaleString(DateTime.DATE_FULL), 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'],
} }
}) })
} }

View file

@ -8,8 +8,13 @@
<li> <li>
<strong>{{ album.date }}: </strong> <strong>{{ album.date }}: </strong>
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}"> <a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
{{ album.title }} by {{ album.artist }} {{ album.title }}
</a> </a>
<span> by </span>
<a href="https://musicbrainz.org/artist/{{ album.mbid }}">
{{ album.artist }}
</a>
<span> • {{ album.genre }}</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>