feat: dry up + normalize now page

This commit is contained in:
Cory Dransfeldt 2023-08-14 11:36:07 -07:00
parent 022ce82f81
commit 6dda493d7b
No known key found for this signature in database
13 changed files with 86 additions and 136 deletions

View file

@ -1,18 +1,25 @@
const ALBUM_DENYLIST = ['no-love-deep-web', 'unremittance']
module.exports = {
artist: (media) =>
`https://cdn.coryd.dev/artists/${media.replace(/\s+/g, '-').toLowerCase()}.jpg` ||
'https://cdn.coryd.dev/artists/missing-artist.jpg',
album: (media) => {
return !ALBUM_DENYLIST.includes(media.name.replace(/\s+/g, '-').toLowerCase())
? media.replace('https://lastfm.freetls.fastly.net', 'https://albums.coryd.dev')
: `https://cdn.coryd.dev/albums/${media.name.replace(/\s+/g, '-').toLowerCase()}.jpg`
},
tv: (episode) =>
`https://cdn.coryd.dev/tv/${episode.replace(':', '').replace(/\s+/g, '-').toLowerCase()}.jpg` ||
'https://cdn.coryd.dev/tv/missing-tv.jpg',
cdn: (url, host, cdn) => {
return url.replace(host, cdn)
},
normalizeMedia: (media) =>
media.map((item) => {
let normalized = {
image: item['image'],
url: item['url'],
}
if (item.type === 'album') {
normalized['title'] = item['title']
normalized['alt'] = `${item['title']} by ${item['artist']}`
normalized['subtext'] = item['artist']
}
if (item.type === 'artist') {
normalized['title'] = item['title']
normalized['subtext'] = `${item['plays']} plays`
}
if (item.type === 'book') normalized['alt'] = item['title']
if (item.type === 'movie') normalized['title'] = item['title']
if (item.type === 'tv') {
normalized['title'] = item['title']
normalized['subtext'] = `${item.name} • <strong>${item.episode}</strong>`
}
return normalized
}),
}