feat: bespoke func to alias artists with too many names (thanks John Dwyer)
This commit is contained in:
parent
f38ad40801
commit
8c000990b2
2 changed files with 24 additions and 8 deletions
|
@ -1,5 +1,20 @@
|
||||||
const { AssetCache } = require('@11ty/eleventy-fetch')
|
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) =>
|
const sortTrim = (array, length = 8) =>
|
||||||
Object.values(array)
|
Object.values(array)
|
||||||
.sort((a, b) => b.plays - a.plays)
|
.sort((a, b) => b.plays - a.plays)
|
||||||
|
@ -55,7 +70,7 @@ module.exports = async function () {
|
||||||
// aggregate artists
|
// aggregate artists
|
||||||
if (!response.artists[track.attributes.artistName]) {
|
if (!response.artists[track.attributes.artistName]) {
|
||||||
response.artists[track.attributes.artistName] = {
|
response.artists[track.attributes.artistName] = {
|
||||||
name: track.attributes.artistName,
|
artist: track.attributes.artistName,
|
||||||
plays: 1,
|
plays: 1,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,15 +93,16 @@ module.exports = async function () {
|
||||||
if (!response.tracks[track.attributes.name]) {
|
if (!response.tracks[track.attributes.name]) {
|
||||||
response.tracks[track.attributes.name] = {
|
response.tracks[track.attributes.name] = {
|
||||||
name: track.attributes.name,
|
name: track.attributes.name,
|
||||||
|
artist: track.attributes.artistName,
|
||||||
plays: 1,
|
plays: 1,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response.tracks[track.attributes.name].plays++
|
response.tracks[track.attributes.name].plays++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
response.artists = sortTrim(response.artists)
|
response.artists = aliasArtists(sortTrim(response.artists))
|
||||||
response.albums = sortTrim(response.albums)
|
response.albums = aliasArtists(sortTrim(response.albums))
|
||||||
response.tracks = sortTrim(response.tracks, 5)
|
response.tracks = aliasArtists(sortTrim(response.tracks, 5))
|
||||||
await asset.save(response, 'json')
|
await asset.save(response, 'json')
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,17 +56,17 @@ layout: main
|
||||||
</h2>
|
</h2>
|
||||||
<div class="grid grid-cols-2 gap-2 md:grid-cols-4 not-prose">
|
<div class="grid grid-cols-2 gap-2 md:grid-cols-4 not-prose">
|
||||||
{% for artist in music.artists %}
|
{% for artist in music.artists %}
|
||||||
<a href="https://rateyourmusic.com/search?searchterm={{ artist.name | escape }}" title="{{artist.name | escape}}">
|
<a href="https://rateyourmusic.com/search?searchterm={{ artist.artist | escape }}" title="{{artist.artist | escape}}">
|
||||||
<div class="relative block">
|
<div class="relative block">
|
||||||
<div class="absolute left-0 top-0 h-full w-full rounded-lg border border-purple-600 hover:border-purple-500 bg-cover-gradient dark:border-purple-400 dark:hover:border-purple-500"></div>
|
<div class="absolute left-0 top-0 h-full w-full rounded-lg border border-purple-600 hover:border-purple-500 bg-cover-gradient dark:border-purple-400 dark:hover:border-purple-500"></div>
|
||||||
<div class="absolute left-1 bottom-2 drop-shadow-md">
|
<div class="absolute left-1 bottom-2 drop-shadow-md">
|
||||||
<div class="px-1 text-xs font-bold text-white line-clamp-2">{{ artist.name }}</div>
|
<div class="px-1 text-xs font-bold text-white line-clamp-2">{{ artist.artist }}</div>
|
||||||
<div class="px-1 text-xs text-white">
|
<div class="px-1 text-xs text-white">
|
||||||
{{ artist.plays }} plays
|
{{ artist.plays }} plays
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{%- capture artistImg %}{{ artist.name | artist }}{% endcapture -%}
|
{%- capture artistImg %}{{ artist.artist | artist }}{% endcapture -%}
|
||||||
{%- capture artistName %}{{ artist.name | escape }}{% endcapture -%}
|
{%- capture artistName %}{{ artist.artist | escape }}{% endcapture -%}
|
||||||
{% image artistImg, artistName, 'rounded-lg', '225px', 'eager' %}
|
{% image artistImg, artistName, 'rounded-lg', '225px', 'eager' %}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
Reference in a new issue