fix: keys are hard

This commit is contained in:
Cory Dransfeldt 2024-04-16 15:39:06 -07:00
parent 8bbfb51441
commit 589dc7aef7
No known key found for this signature in database
2 changed files with 15 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "11.4.12",
"version": "11.4.13",
"description": "The source for my personal site. Built using 11ty.",
"type": "module",
"scripts": {

View file

@ -4,7 +4,7 @@ export const artistCapitalization = (artist) => artistCapitalizationPatches[arti
const sanitizeMediaString = (string) => string.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
const artistSanitizedKey = (artist) => `${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}`
const albumSanitizedKey = (album) => `${sanitizeMediaString(album).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album.replace(/[:\/\\,'']+/g
const albumSanitizedKey = (artist, album) => `${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(album.replace(/[:\/\\,'']+/g
, '').replace(/\s+/g, '-').toLowerCase())}`
export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
@ -15,12 +15,14 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
tracks.forEach(track => {
if (!tracksData[track['track']]) {
const artistKey = artistSanitizedKey(track['artist'])
tracksData[track['track']] = {
artist: artistCapitalization(track['artist']),
title: track['track'],
plays: 1,
type: 'track',
url: (artists[artistSanitizedKey(track['artist'])]?.['mbid'] && artists[artistSanitizedKey(track['artist'])]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistSanitizedKey(track['artist'])]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
url: (artists[artistKey]?.['mbid'] && artists[artistKey]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistKey]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
/\s+/g,
'+'
)}&type=artist`,
@ -30,11 +32,13 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
}
if (!artistsData[artistCapitalization(track['artist'])]) {
const artistKey = artistSanitizedKey(track['artist'])
artistsData[artistCapitalization(track['artist'])] = {
title: artistCapitalization(track['artist']),
plays: 1,
mbid: artists[artistSanitizedKey(track['artist'])]?.['mbid'] || '',
url: (artists[artistSanitizedKey(track['artist'])]?.['mbid'] && artists[artistSanitizedKey(track['artist'])]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistSanitizedKey(track['artist'])]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
mbid: artists[artistKey]?.['mbid'] || '',
url: (artists[artistKey]?.['mbid'] && artists[artistKey]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistKey]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
/\s+/g,
'+'
)}&type=artist`,
@ -46,13 +50,15 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
}
if (!albumsData[track['album']]) {
const albumKey = albumSanitizedKey(artistCapitalization(track['artist']), track['album'])
albumsData[track['album']] = {
title: track['album'],
artist: artistCapitalization(track['artist']),
plays: 1,
mbid: albums[albumSanitizedKey(track['album'])]?.['mbid'] || '',
url: (albums[albumSanitizedKey(track['album'])]?.['mbid'] && albums[albumSanitizedKey(track['album'])]?.['mbid'] !== '') ? `https://musicbrainz.org/release-group/${albums[albumSanitizedKey(track['album'])]?.['mbid']}` : `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${track['artist'].replace(/\s+/g, '+')}&tag-lookup.release=${track['album'].replace(/\s+/g, '+')}`,
image: albums[albumSanitizedKey(track['album'])]?.['image'] || `https://coryd.dev/.netlify/images/?url=https://f001.backblazeb2.com/file/coryd-dev-images/albums/${sanitizeMediaString(track['artist']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(track['album'].replace(/[:\/\\,'']+/g
mbid: albums[albumKey]?.['mbid'] || '',
url: (albums[albumKey]?.['mbid'] && albums[albumSanitizedKey(artistCapitalization(track['artist']), track['artist'], track['album'])]?.['mbid'] !== '') ? `https://musicbrainz.org/release-group/${albums[albumKey]?.['mbid']}` : `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${track['artist'].replace(/\s+/g, '+')}&tag-lookup.release=${track['album'].replace(/\s+/g, '+')}`,
image: albums[albumKey]?.['image'] || `https://coryd.dev/.netlify/images/?url=https://f001.backblazeb2.com/file/coryd-dev-images/albums/${sanitizeMediaString(track['artist']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(track['album'].replace(/[:\/\\,'']+/g
, '').replace(/\s+/g, '-').toLowerCase())}.jpg&fit=cover&w=320&h=320`,
type: 'album'
}
@ -78,7 +84,7 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
export const buildTracksWithArt = (tracks, artists, albums) => {
tracks.forEach(track => {
track['image'] = albums[albumSanitizedKey(track['album'])]?.['image'] || `https://coryd.dev/.netlify/images/?url=https://f001.backblazeb2.com/file/coryd-dev-images/albums/${sanitizeMediaString(track['artist']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(track['album'].replace(/[:\/\\,'']+/g
track['image'] = albums[albumSanitizedKey(artistCapitalization(track['artist']), track['album'])]?.['image'] || `https://coryd.dev/.netlify/images/?url=https://f001.backblazeb2.com/file/coryd-dev-images/albums/${sanitizeMediaString(track['artist']).replace(/\s+/g, '-').toLowerCase()}-${sanitizeMediaString(track['album'].replace(/[:\/\\,'']+/g
, '').replace(/\s+/g, '-').toLowerCase())}.jpg&fit=cover&w=320&h=320`
track['url'] = (artists[artistSanitizedKey(track['artist'])]?.['mbid'] && artists[artistSanitizedKey(track['artist'])]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistSanitizedKey(track['artist'])]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
/\s+/g,