diff options
author | Florrie <towerofnix@gmail.com> | 2020-04-15 16:57:29 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2020-04-15 16:57:29 -0300 |
commit | c2fc55c8644f8ab494c98eb1d413a34a257a8713 (patch) | |
tree | 273ab3d1accec66b20cc905033cc7b7292a3ff56 /upd8.js | |
parent | d3c6ae4fa228d2ef9c8830a8a52c4a4cd4b1abe5 (diff) |
chronology buttons
Diffstat (limited to 'upd8.js')
-rw-r--r-- | upd8.js | 51 |
1 files changed, 47 insertions, 4 deletions
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 && `<a href="${C.TRACK_DIRECTORY}/${previous.directory}/index.html" title="${previous.name}">Previous</a>`, + next && `<a href="${C.TRACK_DIRECTORY}/${next.directory}/index.html" title="${next.name}">Next</a>` + ].filter(Boolean); + + const heading = `${th(index + 1)} ${headingWord} by <a href="${C.ARTIST_DIRECTORY}/${C.getArtistDirectory(artist)}/index.html">${artist}</a>`; + + return parts.length ? fixWS` + <p> + ${heading}<br> + (${parts.join(', ')}) + </p> + ` : fixWS` + <p>${heading}</p> + `; + }).filter(Boolean).join('\n'); +} + function generateSidebarForAlbum(album, currentTrack = null) { const listTag = getAlbumListTag(album); return fixWS` @@ -1522,10 +1551,24 @@ function generateSidebarForAlbum(album, currentTrack = null) { <li class="${track === currentTrack ? 'current' : ''}"><a href="${C.TRACK_DIRECTORY}/${track.directory}/index.html">${track.name}</a></li> `).join('\n')} </${listTag}> - <hr> - <p> - <a href="${C.JS_DISABLED_DIRECTORY}/index.html" data-random="track-in-album">Random track</a></li> - </p> + ${(album.tracks.length > 1 || currentTrack) && `<hr>`} + ${album.tracks.length > 1 && fixWS` + <p> + <a href="${C.JS_DISABLED_DIRECTORY}/index.html" data-random="track-in-album">Random track</a></li> + </p> + `} + ${currentTrack && fixWS` + ${chronologyButtons(currentTrack, { + mapProperty: 'artists', + toArtist: artist => artist, + headingWord: 'track' + })} + ${chronologyButtons(currentTrack, { + mapProperty: 'coverArtists', + toArtist: ({ who }) => who, + headingWord: 'track art' + })} + `} ` } |