diff --git a/package.json b/package.json index 6bb8d65b..2fb09c18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "8.3.9", + "version": "8.4.0", "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 dca30272..a162756c 100644 --- a/src/_data/albums.js +++ b/src/_data/albums.js @@ -1,10 +1,5 @@ import EleventyFetch from '@11ty/eleventy-fetch' -import { artistCapitalization } from './helpers/music.js' - -const removeAccents = (inputStr) => { - const normalizedStr = inputStr.normalize('NFD'); - return normalizedStr.replace(/[\u0300-\u036f]/g, ''); -}; +import { artistCapitalization, sanitizeMediaString } from './helpers/music.js' export default async function () { const MUSIC_KEY = process.env.API_KEY_LASTFM @@ -15,7 +10,7 @@ export default async function () { 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 + image: `https://cdn.coryd.dev/albums/${encodeURIComponent(sanitizeMediaString(album['artist']['name']).replace(/\s+/g, '-').toLowerCase())}-${encodeURIComponent(sanitizeMediaString(album['name'].replace(/[:\/\\,'']+/g , '').replace(/\s+/g, '-').toLowerCase()))}.jpg`, url: album['mbid'] ? `https://musicbrainz.org/album/${album['mbid']}` diff --git a/src/_data/artists.js b/src/_data/artists.js index f4c39242..91827a8a 100644 --- a/src/_data/artists.js +++ b/src/_data/artists.js @@ -1,13 +1,5 @@ import EleventyFetch from '@11ty/eleventy-fetch'; -import mbidPatches from './json/mbid-patches.js'; -import { artistCapitalization } from './helpers/music.js' - -const mbidMap = (artist) => mbidPatches[artist.toLowerCase()] || '' - -const removeAccents = (inputStr) => { - const normalizedStr = inputStr.normalize('NFD'); - return normalizedStr.replace(/[\u0300-\u036f]/g, ''); -}; +import { artistCapitalization, sanitizeMediaString, mbidMap } from './helpers/music.js' export default async function () { const MUSIC_KEY = process.env.API_KEY_LASTFM; @@ -22,7 +14,7 @@ export default async function () { 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`, + image: `https://cdn.coryd.dev/artists/${encodeURIComponent(sanitizeMediaString(artist['name']).replace(/\s+/g, '-').toLowerCase())}.jpg`, url: mbid ? `https://musicbrainz.org/artist/${mbid}` : `https://musicbrainz.org/search?query=${artist['name'].replace( diff --git a/src/_data/helpers/music.js b/src/_data/helpers/music.js index f9582415..b9a69dff 100644 --- a/src/_data/helpers/music.js +++ b/src/_data/helpers/music.js @@ -1,3 +1,11 @@ import artistCapitalizationPatches from '../json/artist-capitalization-patches.js'; +import mbidPatches from '../json/mbid-patches.js'; -export const artistCapitalization = (artist) => artistCapitalizationPatches[artist?.toLowerCase()] || artist \ No newline at end of file +export const artistCapitalization = (artist) => artistCapitalizationPatches[artist?.toLowerCase()] || artist + +export const sanitizeMediaString = (string) => { + const normalizedStr = string.normalize('NFD'); + return normalizedStr.replace(/[\u0300-\u036f]/g, '').replace(/\.{3}/g, ''); +}; + +export const mbidMap = (artist) => mbidPatches[artist.toLowerCase()] || '' \ No newline at end of file