chore: music -> capitalization helper

This commit is contained in:
Cory Dransfeldt 2024-03-19 14:35:02 -07:00
parent 7ae4b0cb4d
commit a8355cfa97
No known key found for this signature in database
5 changed files with 13 additions and 7 deletions

View file

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

View file

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

View file

@ -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`,

View file

@ -0,0 +1,3 @@
import artistCapitalizationPatches from '../json/artist-capitalization-patches.js';
export const artistCapitalization = (artist) => artistCapitalizationPatches[artist] || artist

View file

@ -0,0 +1,3 @@
export default {
civerous: 'Civerous'
}