fix: keys are hard
This commit is contained in:
parent
8bbfb51441
commit
589dc7aef7
2 changed files with 15 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "11.4.12",
|
"version": "11.4.13",
|
||||||
"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": {
|
||||||
|
|
|
@ -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 sanitizeMediaString = (string) => string.normalize('NFD').replace(/[\u0300-\u036f\u2010—\.\?\(\)\[\]\{\}]/g, '').replace(/\.{3}/g, '')
|
||||||
const artistSanitizedKey = (artist) => `${sanitizeMediaString(artist).replace(/\s+/g, '-').toLowerCase()}`
|
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())}`
|
, '').replace(/\s+/g, '-').toLowerCase())}`
|
||||||
|
|
||||||
export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
||||||
|
@ -15,12 +15,14 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
||||||
|
|
||||||
tracks.forEach(track => {
|
tracks.forEach(track => {
|
||||||
if (!tracksData[track['track']]) {
|
if (!tracksData[track['track']]) {
|
||||||
|
const artistKey = artistSanitizedKey(track['artist'])
|
||||||
|
|
||||||
tracksData[track['track']] = {
|
tracksData[track['track']] = {
|
||||||
artist: artistCapitalization(track['artist']),
|
artist: artistCapitalization(track['artist']),
|
||||||
title: track['track'],
|
title: track['track'],
|
||||||
plays: 1,
|
plays: 1,
|
||||||
type: 'track',
|
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,
|
/\s+/g,
|
||||||
'+'
|
'+'
|
||||||
)}&type=artist`,
|
)}&type=artist`,
|
||||||
|
@ -30,11 +32,13 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!artistsData[artistCapitalization(track['artist'])]) {
|
if (!artistsData[artistCapitalization(track['artist'])]) {
|
||||||
|
const artistKey = artistSanitizedKey(track['artist'])
|
||||||
|
|
||||||
artistsData[artistCapitalization(track['artist'])] = {
|
artistsData[artistCapitalization(track['artist'])] = {
|
||||||
title: artistCapitalization(track['artist']),
|
title: artistCapitalization(track['artist']),
|
||||||
plays: 1,
|
plays: 1,
|
||||||
mbid: artists[artistSanitizedKey(track['artist'])]?.['mbid'] || '',
|
mbid: artists[artistKey]?.['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(
|
url: (artists[artistKey]?.['mbid'] && artists[artistKey]?.['mbid'] !== '') ? `http://musicbrainz.org/artist/${artists[artistKey]?.['mbid']}` : `https://musicbrainz.org/search?query=${track['artist'].replace(
|
||||||
/\s+/g,
|
/\s+/g,
|
||||||
'+'
|
'+'
|
||||||
)}&type=artist`,
|
)}&type=artist`,
|
||||||
|
@ -46,13 +50,15 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!albumsData[track['album']]) {
|
if (!albumsData[track['album']]) {
|
||||||
|
const albumKey = albumSanitizedKey(artistCapitalization(track['artist']), track['album'])
|
||||||
|
|
||||||
albumsData[track['album']] = {
|
albumsData[track['album']] = {
|
||||||
title: track['album'],
|
title: track['album'],
|
||||||
artist: artistCapitalization(track['artist']),
|
artist: artistCapitalization(track['artist']),
|
||||||
plays: 1,
|
plays: 1,
|
||||||
mbid: albums[albumSanitizedKey(track['album'])]?.['mbid'] || '',
|
mbid: albums[albumKey]?.['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, '+')}`,
|
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[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
|
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`,
|
, '').replace(/\s+/g, '-').toLowerCase())}.jpg&fit=cover&w=320&h=320`,
|
||||||
type: 'album'
|
type: 'album'
|
||||||
}
|
}
|
||||||
|
@ -78,7 +84,7 @@ export const buildChart = (tracks, artists, albums, nowPlaying = {}) => {
|
||||||
|
|
||||||
export const buildTracksWithArt = (tracks, artists, albums) => {
|
export const buildTracksWithArt = (tracks, artists, albums) => {
|
||||||
tracks.forEach(track => {
|
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`
|
, '').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(
|
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,
|
/\s+/g,
|
||||||
|
|
Reference in a new issue