From c2fc55c8644f8ab494c98eb1d413a34a257a8713 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 15 Apr 2020 16:57:29 -0300 Subject: chronology buttons --- site.css | 6 +++++- upd8.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/site.css b/site.css index 69c580d6..4c993eb1 100644 --- a/site.css +++ b/site.css @@ -69,7 +69,11 @@ a:hover { #sidebar p { text-align: center; - margin: 0; + margin: 0.5em 0; +} + +#sidebar p:last-child { + margin-bottom: 0; } #sidebar hr { diff --git a/upd8.js b/upd8.js index 3c28ee9d..5d094390 100644 --- a/upd8.js +++ b/upd8.js @@ -1511,6 +1511,35 @@ function getAlbumListTag(album) { } } +function chronologyButtons(currentTrack, {mapProperty, toArtist, filterCondition, headingWord}) { + return currentTrack[mapProperty] && currentTrack[mapProperty].map(toArtist).map(artist => { + if (!artistNames.includes(artist)) return ''; + + const releasedTracks = allTracks.filter(track => track.album.directory !== C.UNRELEASED_TRACKS_DIRECTORY && track[mapProperty] && track[mapProperty].map(toArtist).includes(artist)); + const index = releasedTracks.indexOf(currentTrack); + + if (index === -1) return ''; + + const previous = releasedTracks[index - 1]; + const next = releasedTracks[index + 1]; + const parts = [ + previous && `Previous`, + next && `Next` + ].filter(Boolean); + + const heading = `${th(index + 1)} ${headingWord} by ${artist}`; + + return parts.length ? fixWS` +

+ ${heading}
+ (${parts.join(', ')}) +

+ ` : fixWS` +

${heading}

+ `; + }).filter(Boolean).join('\n'); +} + function generateSidebarForAlbum(album, currentTrack = null) { const listTag = getAlbumListTag(album); return fixWS` @@ -1522,10 +1551,24 @@ function generateSidebarForAlbum(album, currentTrack = null) {
  • ${track.name}
  • `).join('\n')} -
    -

    - Random track -

    + ${(album.tracks.length > 1 || currentTrack) && `
    `} + ${album.tracks.length > 1 && fixWS` +

    + Random track +

    + `} + ${currentTrack && fixWS` + ${chronologyButtons(currentTrack, { + mapProperty: 'artists', + toArtist: artist => artist, + headingWord: 'track' + })} + ${chronologyButtons(currentTrack, { + mapProperty: 'coverArtists', + toArtist: ({ who }) => who, + headingWord: 'track art' + })} + `} ` } -- cgit 1.3.0-6-gf8a5