chore: music helpers

This commit is contained in:
Cory Dransfeldt 2024-03-20 16:15:21 -07:00
parent b8c8c926ab
commit 5bcb79a7be
No known key found for this signature in database
4 changed files with 14 additions and 19 deletions

View file

@ -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": {

View file

@ -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']}`

View file

@ -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(

View file

@ -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
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()] || ''