From a8355cfa9729858582a2b08ba949d31a00edfe43 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Tue, 19 Mar 2024 14:35:02 -0700 Subject: [PATCH] chore: music -> capitalization helper --- package.json | 2 +- src/_data/albums.js | 3 ++- src/_data/artists.js | 9 ++++----- src/_data/helpers/music.js | 3 +++ src/_data/json/artist-capitalization-patches.js | 3 +++ 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/_data/helpers/music.js create mode 100644 src/_data/json/artist-capitalization-patches.js diff --git a/package.json b/package.json index 85a21c9a..592d7af0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "8.2.5", + "version": "8.3.5", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/_data/albums.js b/src/_data/albums.js index e865978f..dca30272 100644 --- a/src/_data/albums.js +++ b/src/_data/albums.js @@ -1,4 +1,5 @@ import EleventyFetch from '@11ty/eleventy-fetch' +import { artistCapitalization } from './helpers/music.js' const removeAccents = (inputStr) => { const normalizedStr = inputStr.normalize('NFD'); @@ -11,7 +12,7 @@ export default async function () { const formatAlbumData = (albums) => albums.map((album) => { return { title: album['name'], - artist: album['artist']['name'], + artist: artistCapitalization(album['artist']['name']), plays: album['playcount'], rank: album['@attr']['rank'], image: `https://cdn.coryd.dev/albums/${encodeURIComponent(removeAccents(album['artist']['name']).replace(/\s+/g, '-').toLowerCase())}-${encodeURIComponent(removeAccents(album['name'].replace(/[:\/\\,'']+/g diff --git a/src/_data/artists.js b/src/_data/artists.js index 40bf122a..f4c39242 100644 --- a/src/_data/artists.js +++ b/src/_data/artists.js @@ -1,9 +1,8 @@ import EleventyFetch from '@11ty/eleventy-fetch'; import mbidPatches from './json/mbid-patches.js'; +import { artistCapitalization } from './helpers/music.js' -const mbidMap = (artist) => { - return mbidPatches[artist.toLowerCase()] || ''; -}; +const mbidMap = (artist) => mbidPatches[artist.toLowerCase()] || '' const removeAccents = (inputStr) => { const normalizedStr = inputStr.normalize('NFD'); @@ -14,13 +13,13 @@ export default async function () { const MUSIC_KEY = process.env.API_KEY_LASTFM; const url = `https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=coryd_&api_key=${MUSIC_KEY}&limit=8&format=json&period=7day`; const formatArtistData = (artists) => artists.map((artist) => { - let mbid = artist['mbid']; + let mbid = artist['mbid'] // mbid mismatches if (mbidMap(artist['name']) !== '') mbid = mbidMap(artist['name']); return { - title: artist['name'], + title: artistCapitalization(artist['name']), plays: artist['playcount'], rank: artist['@attr']['rank'], image: `https://cdn.coryd.dev/artists/${encodeURIComponent(removeAccents(artist['name']).replace(/\s+/g, '-').toLowerCase())}.jpg`, diff --git a/src/_data/helpers/music.js b/src/_data/helpers/music.js new file mode 100644 index 00000000..44edc001 --- /dev/null +++ b/src/_data/helpers/music.js @@ -0,0 +1,3 @@ +import artistCapitalizationPatches from '../json/artist-capitalization-patches.js'; + +export const artistCapitalization = (artist) => artistCapitalizationPatches[artist] || artist \ No newline at end of file diff --git a/src/_data/json/artist-capitalization-patches.js b/src/_data/json/artist-capitalization-patches.js new file mode 100644 index 00000000..32831ddf --- /dev/null +++ b/src/_data/json/artist-capitalization-patches.js @@ -0,0 +1,3 @@ +export default { + civerous: 'Civerous' +} \ No newline at end of file