From 8c000990b2f380bee44af74ee2d1066cb57a0533 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Tue, 27 Jun 2023 10:45:39 -0700 Subject: [PATCH] feat: bespoke func to alias artists with too many names (thanks John Dwyer) --- src/_data/music.js | 24 ++++++++++++++++++++---- src/_includes/now.liquid | 8 ++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/_data/music.js b/src/_data/music.js index 408a1468..81a80ef6 100644 --- a/src/_data/music.js +++ b/src/_data/music.js @@ -1,5 +1,20 @@ const { AssetCache } = require('@11ty/eleventy-fetch') +const artistAliases = [ + { + artist: 'Osees', + aliases: ['OCS', 'The Ohsees', 'Thee Oh Sees', "Thee Oh See's"], + }, +] + +const aliasArtists = (array) => { + array.forEach((a) => { + const aliased = artistAliases.find((alias) => alias.aliases.includes(a.artist)) + if (aliased) a.artist = aliased.artist + }) + return array +} + const sortTrim = (array, length = 8) => Object.values(array) .sort((a, b) => b.plays - a.plays) @@ -55,7 +70,7 @@ module.exports = async function () { // aggregate artists if (!response.artists[track.attributes.artistName]) { response.artists[track.attributes.artistName] = { - name: track.attributes.artistName, + artist: track.attributes.artistName, plays: 1, } } else { @@ -78,15 +93,16 @@ module.exports = async function () { if (!response.tracks[track.attributes.name]) { response.tracks[track.attributes.name] = { name: track.attributes.name, + artist: track.attributes.artistName, plays: 1, } } else { response.tracks[track.attributes.name].plays++ } }) - response.artists = sortTrim(response.artists) - response.albums = sortTrim(response.albums) - response.tracks = sortTrim(response.tracks, 5) + response.artists = aliasArtists(sortTrim(response.artists)) + response.albums = aliasArtists(sortTrim(response.albums)) + response.tracks = aliasArtists(sortTrim(response.tracks, 5)) await asset.save(response, 'json') return response } diff --git a/src/_includes/now.liquid b/src/_includes/now.liquid index ebd67631..f72ecadc 100644 --- a/src/_includes/now.liquid +++ b/src/_includes/now.liquid @@ -56,17 +56,17 @@ layout: main
{% for artist in music.artists %} - +
-
{{ artist.name }}
+
{{ artist.artist }}
{{ artist.plays }} plays
- {%- capture artistImg %}{{ artist.name | artist }}{% endcapture -%} - {%- capture artistName %}{{ artist.name | escape }}{% endcapture -%} + {%- capture artistImg %}{{ artist.artist | artist }}{% endcapture -%} + {%- capture artistName %}{{ artist.artist | escape }}{% endcapture -%} {% image artistImg, artistName, 'rounded-lg', '225px', 'eager' %}