diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-04-23 16:48:35 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-30 20:48:18 -0300 |
commit | 5b4f7bd906d658116b384122518c43a577141368 (patch) | |
tree | 82136853f3381873b62fdc6a3de5a883c0260d87 /src/content/dependencies/generateTrackChronologyLinks.js | |
parent | 9d655c9a4c910a9dc02eceb850d393832a105fba (diff) |
content: generateTrackChronologyLinks: inline scoping logic
Diffstat (limited to 'src/content/dependencies/generateTrackChronologyLinks.js')
-rw-r--r-- | src/content/dependencies/generateTrackChronologyLinks.js | 116 |
1 files changed, 102 insertions, 14 deletions
diff --git a/src/content/dependencies/generateTrackChronologyLinks.js b/src/content/dependencies/generateTrackChronologyLinks.js index accb9ef1..fd676942 100644 --- a/src/content/dependencies/generateTrackChronologyLinks.js +++ b/src/content/dependencies/generateTrackChronologyLinks.js @@ -1,30 +1,118 @@ +import {sortAlbumsTracksChronologically} from '#sort'; + +import getChronologyRelations from '../util/getChronologyRelations.js'; + export default { contentDependencies: [ + 'generateChronologyLinks', 'generateChronologyLinksScopeSwitcher', - 'generateScopedTrackChronologyLinks', + 'linkAlbum', + 'linkArtist', + 'linkTrack', ], - relations: (relation, track) => ({ - scopeSwitcher: - relation('generateChronologyLinksScopeSwitcher'), + relations(relation, track) { + function getScopedRelations(album) { + const albumFilter = + (album + ? track => track.album === album + : () => true); + + return { + chronologyLinks: + relation('generateChronologyLinks'), + + artistChronologyContributions: + getChronologyRelations(track, { + contributions: [ + ...track.artistContribs ?? [], + ...track.contributorContribs ?? [], + ], + + linkArtist: artist => relation('linkArtist', artist), + linkThing: track => relation('linkTrack', track), + + getThings(artist) { + const getDate = thing => thing.date; + + const things = + ([ + ...artist.tracksAsArtist, + ...artist.tracksAsContributor, + ]).filter(getDate) + .filter(albumFilter); + + return sortAlbumsTracksChronologically(things, {getDate}); + }, + }), + + coverArtistChronologyContributions: + getChronologyRelations(track, { + contributions: track.coverArtistContribs ?? [], + + linkArtist: artist => relation('linkArtist', artist), + + linkThing: trackOrAlbum => + (trackOrAlbum.album + ? relation('linkTrack', trackOrAlbum) + : relation('linkAlbum', trackOrAlbum)), + + getThings(artist) { + const getDate = thing => thing.coverArtDate ?? thing.date; + + const things = + ([ + ...artist.albumsAsCoverArtist, + ...artist.tracksAsCoverArtist, + ]).filter(getDate) + .filter(albumFilter); + + return sortAlbumsTracksChronologically(things, {getDate}); + }, + }), + }; + } + + return { + scopeSwitcher: + relation('generateChronologyLinksScopeSwitcher'), + + wiki: + getScopedRelations(null), + + album: + getScopedRelations(track.album), + }; + }, - wikiChronologyLinks: - relation('generateScopedTrackChronologyLinks', null, track), + generate(relations) { + function slotScopedRelations(scope) { + return scope.chronologyLinks.slots({ + showOnly: true, - albumChronologyLinks: - relation('generateScopedTrackChronologyLinks', track.album, track), - }), + chronologyInfoSets: [ + { + headingString: 'misc.chronology.heading.track', + contributions: scope.artistChronologyContributions, + }, + { + headingString: 'misc.chronology.heading.coverArt', + contributions: scope.coverArtistChronologyContributions, + }, + ], + }); + } - generate: (relations) => - relations.scopeSwitcher.slots({ + return relations.scopeSwitcher.slots({ scopes: [ 'wiki', 'album', ], contents: [ - relations.wikiChronologyLinks, - relations.albumChronologyLinks, + slotScopedRelations(relations.wiki), + slotScopedRelations(relations.album), ], - }), + }); + }, }; |