From d278cc4537b247dbfb3ccf806b5065e1642c8cb4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 16 Jul 2023 11:59:14 -0300 Subject: content: generateAlbumGalleryCoverArtistsLine --- .../generateAlbumGalleryCoverArtistsLine.js | 20 +++++++ .../dependencies/generateAlbumGalleryInfoLine.js | 38 ------------- .../dependencies/generateAlbumGalleryPage.js | 65 ++++++++++++++++++---- .../dependencies/generateAlbumGalleryStatsLine.js | 38 +++++++++++++ 4 files changed, 112 insertions(+), 49 deletions(-) create mode 100644 src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js delete mode 100644 src/content/dependencies/generateAlbumGalleryInfoLine.js create mode 100644 src/content/dependencies/generateAlbumGalleryStatsLine.js (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js b/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js new file mode 100644 index 00000000..0c6d800b --- /dev/null +++ b/src/content/dependencies/generateAlbumGalleryCoverArtistsLine.js @@ -0,0 +1,20 @@ +export default { + contentDependencies: ['linkArtistGallery'], + extraDependencies: ['html', 'language'], + + relations(relation, coverArtists) { + return { + coverArtistLinks: + coverArtists + .map(artist => relation('linkArtistGallery', artist)), + }; + }, + + generate(relations, {html, language}) { + return ( + html.tag('p', {class: 'quick-info'}, + language.$('albumGalleryPage.coverArtistsLine', { + artists: relations.coverArtistLinks, + }))); + }, +}; diff --git a/src/content/dependencies/generateAlbumGalleryInfoLine.js b/src/content/dependencies/generateAlbumGalleryInfoLine.js deleted file mode 100644 index d4bd4d75..00000000 --- a/src/content/dependencies/generateAlbumGalleryInfoLine.js +++ /dev/null @@ -1,38 +0,0 @@ -import {getTotalDuration} from '../../util/wiki-data.js'; - -export default { - extraDependencies: ['html', 'language'], - - data(album) { - return { - name: album.name, - date: album.date, - duration: getTotalDuration(album.tracks), - numTracks: album.tracks.length, - }; - }, - - generate(data, {html, language}) { - const parts = ['albumGalleryPage.infoLine']; - const options = {}; - - options.tracks = - html.tag('b', - language.countTracks(data.numTracks, {unit: true})); - - options.duration = - html.tag('b', - language.formatDuration(data.duration, {unit: true})); - - if (data.date) { - parts.push('withDate'); - options.date = - html.tag('b', - language.formatDate(data.date)); - } - - return ( - html.tag('p', {class: 'quick-info'}, - language.formatString(parts.join('.'), options))); - }, -}; diff --git a/src/content/dependencies/generateAlbumGalleryPage.js b/src/content/dependencies/generateAlbumGalleryPage.js index b39b4c80..c88d1768 100644 --- a/src/content/dependencies/generateAlbumGalleryPage.js +++ b/src/content/dependencies/generateAlbumGalleryPage.js @@ -1,8 +1,9 @@ -import {stitchArrays} from '../../util/sugar.js'; +import {compareArrays, stitchArrays} from '../../util/sugar.js'; export default { contentDependencies: [ - 'generateAlbumGalleryInfoLine', + 'generateAlbumGalleryCoverArtistsLine', + 'generateAlbumGalleryStatsLine', 'generateAlbumNavAccent', 'generateAlbumStyleRules', 'generateColorStyleRules', @@ -15,7 +16,36 @@ export default { extraDependencies: ['html', 'language'], - relations(relation, album) { + query(album) { + const query = {}; + + const tracksWithUniqueCoverArt = + album.tracks + .filter(track => track.hasUniqueCoverArt); + + // Don't display "all artwork by..." for albums where there's + // only one unique artwork in the first place. + if (tracksWithUniqueCoverArt.length > 1) { + const allCoverArtistArrays = + tracksWithUniqueCoverArt + .map(track => track.coverArtistContribs) + .map(contribs => contribs.map(contrib => contrib.who)); + + const allSameCoverArtists = + allCoverArtistArrays + .slice(1) + .every(artists => compareArrays(artists, allCoverArtistArrays[0])); + + if (allSameCoverArtists) { + query.coverArtistsForAllTracks = + allCoverArtistArrays[0]; + } + } + + return query; + }, + + relations(relation, query, album) { const relations = {}; relations.layout = @@ -33,8 +63,13 @@ export default { relations.albumNavAccent = relation('generateAlbumNavAccent', album, null); - relations.infoLine = - relation('generateAlbumGalleryInfoLine', album); + relations.statsLine = + relation('generateAlbumGalleryStatsLine', album); + + if (query.coverArtistsForAllTracks) { + relations.coverArtistsLine = + relation('generateAlbumGalleryCoverArtistsLine', query.coverArtistsForAllTracks); + } relations.coverGrid = relation('generateCoverGrid'); @@ -52,7 +87,7 @@ export default { return relations; }, - data(album) { + data(query, album) { const data = {}; data.name = album.name; @@ -61,10 +96,17 @@ export default { album.tracks.map(track => track.name); data.coverArtists = - album.tracks.map(track => - (track.hasUniqueCoverArt - ? track.coverArtistContribs.map(({who: artist}) => artist.name) - : null)); + album.tracks.map(track => { + if (query.coverArtistsForAllTracks) { + return null; + } + + if (track.hasUniqueCoverArt) { + return track.coverArtistContribs.map(({who: artist}) => artist.name); + } + + return null; + }); data.paths = album.tracks.map(track => @@ -90,7 +132,8 @@ export default { mainClasses: ['top-index'], mainContent: [ - relations.infoLine, + relations.statsLine, + relations.coverArtistsLine, relations.coverGrid .slots({ diff --git a/src/content/dependencies/generateAlbumGalleryStatsLine.js b/src/content/dependencies/generateAlbumGalleryStatsLine.js new file mode 100644 index 00000000..df36084c --- /dev/null +++ b/src/content/dependencies/generateAlbumGalleryStatsLine.js @@ -0,0 +1,38 @@ +import {getTotalDuration} from '../../util/wiki-data.js'; + +export default { + extraDependencies: ['html', 'language'], + + data(album) { + return { + name: album.name, + date: album.date, + duration: getTotalDuration(album.tracks), + numTracks: album.tracks.length, + }; + }, + + generate(data, {html, language}) { + const parts = ['albumGalleryPage.statsLine']; + const options = {}; + + options.tracks = + html.tag('b', + language.countTracks(data.numTracks, {unit: true})); + + options.duration = + html.tag('b', + language.formatDuration(data.duration, {unit: true})); + + if (data.date) { + parts.push('withDate'); + options.date = + html.tag('b', + language.formatDate(data.date)); + } + + return ( + html.tag('p', {class: 'quick-info'}, + language.formatString(parts.join('.'), options))); + }, +}; -- cgit 1.3.0-6-gf8a5