diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-07-25 04:45:02 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-07-25 04:45:02 -0300 |
commit | 39dfd7bb398adf3c6e4aee6a5bc56fff2098a24c (patch) | |
tree | bb22f9b8703fa12417047c9e50f068f2bd1cc172 | |
parent | 41186f67936dc2fd193dc9ad281403b660f9b911 (diff) |
content: generateGroupGalleryPageAlbumGridTab (factor out)
-rw-r--r-- | src/content/dependencies/generateGroupGalleryPageAlbumGrid.js | 67 | ||||
-rw-r--r-- | src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js | 60 |
2 files changed, 70 insertions, 57 deletions
diff --git a/src/content/dependencies/generateGroupGalleryPageAlbumGrid.js b/src/content/dependencies/generateGroupGalleryPageAlbumGrid.js index 9167a5ad..7b90fd68 100644 --- a/src/content/dependencies/generateGroupGalleryPageAlbumGrid.js +++ b/src/content/dependencies/generateGroupGalleryPageAlbumGrid.js @@ -1,43 +1,17 @@ -import {empty, stitchArrays} from '#sugar'; +import {stitchArrays} from '#sugar'; import {getTotalDuration} from '#wiki-data'; export default { contentDependencies: [ - 'generateArtistCredit', 'generateCoverGrid', + 'generateGroupGalleryPageAlbumGridTab', 'image', 'linkAlbum', ], extraDependencies: ['language', 'wikiData'], - query: (albums, group) => ({ - notedGroups: - albums.map(album => { - const contextGroup = group; - - const candidateGroups = - album.groups - .filter(group => !group.excludeFromGalleryTabs) - .filter(group => group.category !== contextGroup.category); - - return candidateGroups.at(0) ?? null; - }), - - notedArtistContribs: - albums.map(album => { - if ( - album.artistContribs.length === 1 && - !empty(group.closelyLinkedArtists) && - (album.artistContribs[0].artist.name === - group.closelyLinkedArtists[0].artist.name) - ) { - return []; - } - - return album.artistContribs; - }), - + query: (albums, _group) => ({ artworks: albums.map(album => (album.hasCoverArt @@ -45,14 +19,10 @@ export default { : null)), }), - relations: (relation, query, albums, _group) => ({ + relations: (relation, query, albums, group) => ({ coverGrid: relation('generateCoverGrid'), - artistCredits: - query.notedArtistContribs - .map(contribs => relation('generateArtistCredit', contribs, [])), - links: albums .map(album => relation('linkAlbum', album)), @@ -60,6 +30,11 @@ export default { images: query.artworks .map(artwork => relation('image', artwork)), + + tabs: + albums + .map(album => + relation('generateGroupGalleryPageAlbumGridTab', album, group)), }), data: (query, albums, group) => ({ @@ -81,10 +56,6 @@ export default { ? null : getTotalDuration(album.tracks))), - groupNames: - query.notedGroups - .map(group => group ? group.name : null), - notFromThisGroup: albums.map(album => !album.groups.includes(group)), }), @@ -111,25 +82,7 @@ export default { itemAttributes: data.styles.map(style => ({'data-style': style})), - tab: - language.encapsulate(capsule, 'tab', capsule => - stitchArrays({ - groupName: data.groupNames, - artistCredit: relations.artistCredits, - }).map(({groupName, artistCredit}) => - (groupName - ? language.$(capsule, 'group', { - group: groupName, - }) - : artistCredit - ? artistCredit?.slots({ - normalStringKey: - capsule + '.artists', - - normalFeaturingStringKey: - capsule + '.artists.featuring', - }) - : null))), + tab: relations.tabs, info: stitchArrays({ diff --git a/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js b/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js new file mode 100644 index 00000000..597c5227 --- /dev/null +++ b/src/content/dependencies/generateGroupGalleryPageAlbumGridTab.js @@ -0,0 +1,60 @@ +import {empty} from '#sugar'; + +export default { + contentDependencies: ['generateArtistCredit'], + extraDependencies: ['language'], + + query(album, group) { + const query = {}; + + const contextGroup = group; + + const candidateGroups = + album.groups + .filter(group => !group.excludeFromGalleryTabs) + .filter(group => group.category !== contextGroup.category); + + query.notedGroup = candidateGroups.at(0) ?? null; + + if ( + album.artistContribs.length === 1 && + !empty(group.closelyLinkedArtists) && + (album.artistContribs[0].artist.name === + group.closelyLinkedArtists[0].artist.name) + ) { + query.notedArtistContribs = []; + } else { + query.notedArtistContribs = album.artistContribs; + } + + return query; + }, + + relations: (relation, query, _album, _group) => ({ + artistCredit: + relation('generateArtistCredit', query.notedArtistContribs, []), + }), + + data: (query, _album, _group) => ({ + groupName: + (query.notedGroup + ? query.notedGroup.name + : null), + }), + + generate: (data, relations, {language}) => + language.encapsulate('misc.coverGrid.tab', capsule => + (data.groupName + ? language.$(capsule, 'group', { + group: data.groupName, + }) + : relations.artistCredit + ? relations.artistCredit.slots({ + normalStringKey: + capsule + '.artists', + + normalFeaturingStringKey: + capsule + '.artists.featuring', + }) + : null)), +}; |