diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-06-12 18:16:31 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-06-18 22:56:10 -0300 |
commit | 113d63482157dea70f1615f40f3cc8fd43ddd8bf (patch) | |
tree | 1eaf2ef3712d3b673eebb8eaff86fc2629ae438d /src | |
parent | 564fc154fc74e48aeec1691d963b39c1910e63db (diff) |
content: generateArtistInfoPage: content function syntax cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/content/dependencies/generateArtistInfoPage.js | 550 |
1 files changed, 265 insertions, 285 deletions
diff --git a/src/content/dependencies/generateArtistInfoPage.js b/src/content/dependencies/generateArtistInfoPage.js index 88e501ce..dd56b757 100644 --- a/src/content/dependencies/generateArtistInfoPage.js +++ b/src/content/dependencies/generateArtistInfoPage.js @@ -11,309 +11,289 @@ export default { 'generateContentHeading', 'generateCoverArtwork', 'generatePageLayout', - 'linkAlbum', 'linkArtistGallery', 'linkExternal', - 'linkGroup', - 'linkTrack', 'transformContent', ], - extraDependencies: ['html', 'language', 'wikiData'], - - sprawl({wikiInfo}) { - return { - enableFlashesAndGames: wikiInfo.enableFlashesAndGames, - }; - }, - - query(sprawl, artist) { - return { - // Even if an artist has served as both "artist" (compositional) and - // "contributor" (instruments, production, etc) on the same track, that - // track only counts as one unique contribution in the list. - allTracks: - unique( - ([ - artist.trackArtistContributions, - artist.trackContributorContributions, - ]).flat() - .map(({thing}) => thing)), - - // Artworks are different, though. We intentionally duplicate album data - // objects when the artist has contributed some combination of cover art, - // wallpaper, and banner - these each count as a unique contribution. - allArtworks: + extraDependencies: ['html', 'language'], + + query: (artist) => ({ + // Even if an artist has served as both "artist" (compositional) and + // "contributor" (instruments, production, etc) on the same track, that + // track only counts as one unique contribution in the list. + allTracks: + unique( ([ - artist.albumCoverArtistContributions, - artist.albumWallpaperArtistContributions, - artist.albumBannerArtistContributions, - artist.trackCoverArtistContributions, + artist.trackArtistContributions, + artist.trackContributorContributions, ]).flat() - .map(({thing}) => thing), - - // Banners and wallpapers don't show up in the artist gallery page, only - // cover art. - hasGallery: - !empty(artist.albumCoverArtistContributions) || - !empty(artist.trackCoverArtistContributions), - }; - }, - - relations(relation, query, sprawl, artist) { - const relations = {}; - const sections = relations.sections = {}; - - relations.layout = - relation('generatePageLayout'); - - relations.artistNavLinks = - relation('generateArtistNavLinks', artist); - - if (artist.hasAvatar) { - relations.cover = - relation('generateCoverArtwork', []); - } - - if (artist.contextNotes) { - const contextNotes = sections.contextNotes = {}; - contextNotes.content = relation('transformContent', artist.contextNotes); - } - - if (!empty(artist.urls)) { - const visit = sections.visit = {}; - visit.externalLinks = - artist.urls.map(url => - relation('linkExternal', url)); - } - - if (!empty(query.allTracks)) { - const tracks = sections.tracks = {}; - tracks.heading = relation('generateContentHeading'); - tracks.list = relation('generateArtistInfoPageTracksChunkedList', artist); - tracks.groupInfo = relation('generateArtistGroupContributionsInfo', query.allTracks); - } - - if (!empty(query.allArtworks)) { - const artworks = sections.artworks = {}; - artworks.heading = relation('generateContentHeading'); - artworks.list = relation('generateArtistInfoPageArtworksChunkedList', artist); - artworks.groupInfo = - relation('generateArtistGroupContributionsInfo', query.allArtworks); - - if (query.hasGallery) { - artworks.artistGalleryLink = - relation('linkArtistGallery', artist); - } - } - - if (sprawl.enableFlashesAndGames && !empty(artist.flashContributorContributions)) { - const flashes = sections.flashes = {}; - flashes.heading = relation('generateContentHeading'); - flashes.list = relation('generateArtistInfoPageFlashesChunkedList', artist); - } - - if (!empty(artist.albumsAsCommentator) || !empty(artist.tracksAsCommentator)) { - const commentary = sections.commentary = {}; - commentary.heading = relation('generateContentHeading'); - commentary.list = relation('generateArtistInfoPageCommentaryChunkedList', artist); - } - - return relations; - }, - - data(query, sprawl, artist) { - const data = {}; - - data.name = artist.name; - data.directory = artist.directory; - - if (artist.hasAvatar) { - data.avatarFileExtension = artist.avatarFileExtension; - } - - data.totalTrackCount = query.allTracks.length; - data.totalDuration = artist.totalDuration; - - return data; - }, - - generate(data, relations, {html, language}) { - const {sections: sec} = relations; - - return relations.layout - .slots({ - title: data.name, - headingMode: 'sticky', - - cover: - (relations.cover - ? relations.cover.slots({ - path: [ - 'media.artistAvatar', - data.directory, - data.avatarFileExtension, - ], - }) - : null), - - mainContent: [ - sec.contextNotes && [ - html.tag('p', - language.$('releaseInfo.note')), - - html.tag('blockquote', - sec.contextNotes.content), - ], + .map(({thing}) => thing)), + + // Artworks are different, though. We intentionally duplicate album data + // objects when the artist has contributed some combination of cover art, + // wallpaper, and banner - these each count as a unique contribution. + allArtworks: + ([ + artist.albumCoverArtistContributions, + artist.albumWallpaperArtistContributions, + artist.albumBannerArtistContributions, + artist.trackCoverArtistContributions, + ]).flat() + .map(({thing}) => thing), + + // Banners and wallpapers don't show up in the artist gallery page, only + // cover art. + hasGallery: + !empty(artist.albumCoverArtistContributions) || + !empty(artist.trackCoverArtistContributions), + }), + + relations: (relation, query, artist) => ({ + layout: + relation('generatePageLayout'), + + artistNavLinks: + relation('generateArtistNavLinks', artist), + + cover: + (artist.hasAvatar + ? relation('generateCoverArtwork', []) + : null), + + contentHeading: + relation('generateContentHeading'), + + contextNotes: + relation('transformContent', artist.contextNotes), + + visitLinks: + artist.urls + .map(url => relation('linkExternal', url)), + + tracksChunkedList: + relation('generateArtistInfoPageTracksChunkedList', artist), + + tracksGroupInfo: + relation('generateArtistGroupContributionsInfo', query.allTracks), + + artworksChunkedList: + relation('generateArtistInfoPageArtworksChunkedList', artist), + + artworksGroupInfo: + relation('generateArtistGroupContributionsInfo', query.allArtworks), + + artistGalleryLink: + (query.hasGallery + ? relation('linkArtistGallery', artist) + : null), + + flashesChunkedList: + relation('generateArtistInfoPageFlashesChunkedList', artist), + + commentaryChunkedList: + relation('generateArtistInfoPageCommentaryChunkedList', artist), + }), + + data: (query, artist) => ({ + name: + artist.name, + + directory: + artist.directory, + + avatarFileExtension: + (artist.hasAvatar + ? artist.avatarFileExtension + : null), + + totalTrackCount: + query.allTracks.length, + + totalDuration: + artist.totalDuration, + }), + + generate: (data, relations, {html, language}) => + relations.layout.slots({ + title: data.name, + headingMode: 'sticky', + + cover: + (relations.cover + ? relations.cover.slots({ + path: [ + 'media.artistAvatar', + data.directory, + data.avatarFileExtension, + ], + }) + : null), + + mainContent: [ + html.tags([ + html.tag('p', + {[html.onlyIfSiblings]: true}, + language.$('releaseInfo.note')), + + html.tag('blockquote', + {[html.onlyIfContent]: true}, + relations.contextNotes), + ]), + + html.tag('p', + {[html.onlyIfContent]: true}, + language.$('releaseInfo.visitOn', { + [language.onlyIfOptions]: ['links'], + links: + language.formatDisjunctionList( + relations.visitLinks + .map(link => link.slot('context', 'artist'))), + })), + + html.tag('p', + {[html.onlyIfContent]: true}, + language.$('artistPage.viewArtGallery', { + [language.onlyIfOptions]: ['link'], + link: + relations.artistGalleryLink?.slots({ + content: language.$('artistPage.viewArtGallery.link'), + }), + })), + + html.tag('p', + {[html.onlyIfContent]: true}, + language.$('misc.jumpTo.withLinks', { + [language.onlyIfOptions]: ['links'], + links: + language.formatUnitList([ + !html.isBlank(relations.tracksChunkedList) && + html.tag('a', + {href: '#tracks'}, + language.$('artistPage.trackList.title')), + + !html.isBlank(relations.artworksChunkedList) && + html.tag('a', + {href: '#art'}, + language.$('artistPage.artList.title')), + + !html.isBlank(relations.flashesChunkedList) && + html.tag('a', + {href: '#flashes'}, + language.$('artistPage.flashList.title')), + + !html.isBlank(relations.commentaryChunkedList) && + html.tag('a', + {href: '#commentary'}, + language.$('artistPage.commentaryList.title')), + ].filter(Boolean)), + })), + + html.tags([ + relations.contentHeading.clone() + .slots({ + tag: 'h2', + attributes: {id: 'tracks'}, + title: language.$('artistPage.trackList.title'), + }), - sec.visit && + data.totalDuration > 0 && html.tag('p', - language.$('releaseInfo.visitOn', { - links: - language.formatDisjunctionList( - sec.visit.externalLinks - .map(link => link.slot('context', 'artist'))), + {[html.onlyIfSiblings]: true}, + language.$('artistPage.contributedDurationLine', { + artist: data.name, + duration: + language.formatDuration(data.totalDuration, { + approximate: data.totalTrackCount > 1, + unit: true, + }), })), - sec.artworks?.artistGalleryLink && - html.tag('p', - language.$('artistPage.viewArtGallery', { - link: sec.artworks.artistGalleryLink.slots({ - content: language.$('artistPage.viewArtGallery.link'), + relations.tracksChunkedList.slots({ + groupInfo: [ + relations.tracksGroupInfo + .clone() + .slots({ + title: language.$('artistPage.groupContributions.title.music'), + showSortButton: true, + sort: 'count', + countUnit: 'tracks', + visible: true, }), - })), - (sec.tracks || sec.artworsk || sec.flashes || sec.commentary) && - html.tag('p', - language.$('misc.jumpTo.withLinks', { - links: language.formatUnitList( - [ - sec.tracks && - html.tag('a', - {href: '#tracks'}, - language.$('artistPage.trackList.title')), - - sec.artworks && - html.tag('a', - {href: '#art'}, - language.$('artistPage.artList.title')), - - sec.flashes && - html.tag('a', - {href: '#flashes'}, - language.$('artistPage.flashList.title')), - - sec.commentary && - html.tag('a', - {href: '#commentary'}, - language.$('artistPage.commentaryList.title')), - ].filter(Boolean)), - })), - - sec.tracks && [ - sec.tracks.heading - .slots({ - tag: 'h2', - attributes: {id: 'tracks'}, - title: language.$('artistPage.trackList.title'), - }), + relations.tracksGroupInfo + .clone() + .slots({ + title: language.$('artistPage.groupContributions.title.music'), + showSortButton: true, + sort: 'duration', + countUnit: 'tracks', + visible: false, + }), + ], + }), + ]), - data.totalDuration > 0 && - html.tag('p', - language.$('artistPage.contributedDurationLine', { - artist: data.name, - duration: - language.formatDuration(data.totalDuration, { - approximate: data.totalTrackCount > 1, - unit: true, - }), - })), - - sec.tracks.list - .slots({ - groupInfo: [ - sec.tracks.groupInfo - .clone() - .slots({ - title: language.$('artistPage.groupContributions.title.music'), - showSortButton: true, - sort: 'count', - countUnit: 'tracks', - visible: true, - }), - - sec.tracks.groupInfo - .clone() - .slots({ - title: language.$('artistPage.groupContributions.title.music'), - showSortButton: true, - sort: 'duration', - countUnit: 'tracks', - visible: false, - }), - ], - }), - ], - - sec.artworks && [ - sec.artworks.heading - .slots({ - tag: 'h2', - attributes: {id: 'art'}, - title: language.$('artistPage.artList.title'), - }), + html.tags([ + relations.contentHeading.clone() + .slots({ + tag: 'h2', + attributes: {id: 'art'}, + title: language.$('artistPage.artList.title'), + }), + + html.tag('p', + {[html.onlyIfContent]: true}, + language.$('artistPage.viewArtGallery.orBrowseList', { + [language.onlyIfOptions]: ['link'], + link: + relations.artistGalleryLink?.slots({ + content: language.$('artistPage.viewArtGallery.link'), + }), + })), - sec.artworks.artistGalleryLink && - html.tag('p', - language.$('artistPage.viewArtGallery.orBrowseList', { - link: sec.artworks.artistGalleryLink.slots({ - content: language.$('artistPage.viewArtGallery.link'), + relations.artworksChunkedList + .slots({ + groupInfo: + relations.artworksGroupInfo + .slots({ + title: language.$('artistPage.groupContributions.title.artworks'), + showBothColumns: false, + sort: 'count', + countUnit: 'artworks', }), - })), - - sec.artworks.list - .slots({ - groupInfo: - sec.artworks.groupInfo - .slots({ - title: language.$('artistPage.groupContributions.title.artworks'), - showBothColumns: false, - sort: 'count', - countUnit: 'artworks', - }), - }), - ], - - sec.flashes && [ - sec.flashes.heading - .slots({ - tag: 'h2', - attributes: {id: 'flashes'}, - title: language.$('artistPage.flashList.title'), - }), - - sec.flashes.list, - ], + }), + ]), - sec.commentary && [ - sec.commentary.heading - .slots({ - tag: 'h2', - attributes: {id: 'commentary'}, - title: language.$('artistPage.commentaryList.title'), - }), + html.tags([ + relations.contentHeading.clone() + .slots({ + tag: 'h2', + attributes: {id: 'flashes'}, + title: language.$('artistPage.flashList.title'), + }), - sec.commentary.list, - ], - ], + relations.flashesChunkedList, + ]), - navLinkStyle: 'hierarchical', - navLinks: - relations.artistNavLinks + html.tags([ + relations.contentHeading.clone() .slots({ - showExtraLinks: true, - }) - .content, - }); - }, + tag: 'h2', + attributes: {id: 'commentary'}, + title: language.$('artistPage.commentaryList.title'), + }), + + relations.commentaryChunkedList, + ]), + ], + + navLinkStyle: 'hierarchical', + navLinks: + relations.artistNavLinks + .slots({ + showExtraLinks: true, + }) + .content, + }), }; |