From a2413a5a08ded1fdf1b039bd992565827cda46ab Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 6 Jun 2023 20:03:23 -0300 Subject: content: generate{Album,Track}CoverArtwork Portable functions hoo-ray! --- .../dependencies/generateAlbumCoverArtwork.js | 23 +++++++++++++++ .../dependencies/generateAlbumInfoPageContent.js | 7 ++--- .../dependencies/generateTrackCoverArtwork.js | 29 +++++++++++++++++++ .../dependencies/generateTrackInfoPageContent.js | 33 ++++++---------------- 4 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 src/content/dependencies/generateAlbumCoverArtwork.js create mode 100644 src/content/dependencies/generateTrackCoverArtwork.js (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumCoverArtwork.js b/src/content/dependencies/generateAlbumCoverArtwork.js new file mode 100644 index 00000000..f7e86303 --- /dev/null +++ b/src/content/dependencies/generateAlbumCoverArtwork.js @@ -0,0 +1,23 @@ +export default { + contentDependencies: ['generateCoverArtwork'], + + relations(relation, album) { + return { + coverArtwork: + relation('generateCoverArtwork', album.artTags), + }; + }, + + data(album) { + return { + path: ['media.albumCover', album.directory, album.coverArtFileExtension], + }; + }, + + generate(data, relations) { + return relations.coverArtwork + .slots({ + path: data.path, + }); + }, +}; diff --git a/src/content/dependencies/generateAlbumInfoPageContent.js b/src/content/dependencies/generateAlbumInfoPageContent.js index 5d2817ee..230d7351 100644 --- a/src/content/dependencies/generateAlbumInfoPageContent.js +++ b/src/content/dependencies/generateAlbumInfoPageContent.js @@ -4,9 +4,9 @@ export default { contentDependencies: [ 'generateAdditionalFilesShortcut', 'generateAlbumAdditionalFilesList', + 'generateAlbumCoverArtwork', 'generateAlbumTrackList', 'generateContentHeading', - 'generateCoverArtwork', 'linkAlbumCommentary', 'linkAlbumGallery', 'linkContribution', @@ -35,7 +35,7 @@ export default { if (album.hasCoverArt) { relations.cover = - relation('generateCoverArtwork', album.artTags); + relation('generateAlbumCoverArtwork', album); releaseInfo.coverArtistContributionLinks = contributionLinksRelation(album.coverArtistContribs); } else { @@ -161,8 +161,7 @@ export default { if (data.hasCoverArt) { content.cover = relations.cover .slots({ - path: ['media.albumCover', data.coverArtDirectory, data.coverArtFileExtension], - alt: language.$('misc.alt.trackCover') + alt: language.$('misc.alt.albumCover'), }); } else { content.cover = null; diff --git a/src/content/dependencies/generateTrackCoverArtwork.js b/src/content/dependencies/generateTrackCoverArtwork.js new file mode 100644 index 00000000..f6084f36 --- /dev/null +++ b/src/content/dependencies/generateTrackCoverArtwork.js @@ -0,0 +1,29 @@ +export default { + contentDependencies: ['generateCoverArtwork'], + + relations(relation, track) { + return { + coverArtwork: + relation('generateCoverArtwork', + (track.hasUniqueCoverArt + ? track.artTags + : album.artTags)), + }; + }, + + data(track) { + return { + path: + (track.hasUniqueCoverArt + ? ['media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension] + : ['media.albumCover', track.album.directory, track.album.coverArtFileExtension]), + }; + }, + + generate(data, relations) { + return relations.coverArtwork + .slots({ + path: data.path, + }); + }, +}; diff --git a/src/content/dependencies/generateTrackInfoPageContent.js b/src/content/dependencies/generateTrackInfoPageContent.js index c33c2f62..43f8e689 100644 --- a/src/content/dependencies/generateTrackInfoPageContent.js +++ b/src/content/dependencies/generateTrackInfoPageContent.js @@ -6,7 +6,7 @@ export default { 'generateAdditionalFilesShortcut', 'generateAlbumAdditionalFilesList', 'generateContentHeading', - 'generateCoverArtwork', + 'generateTrackCoverArtwork', 'generateTrackList', 'generateTrackListDividedByGroups', 'linkAlbum', @@ -43,6 +43,11 @@ export default { list: relation('generateAlbumAdditionalFilesList', album, additionalFiles), }); + if (track.hasUniqueCoverArt || album.hasCoverArt) { + relations.cover = + relation('generateTrackCoverArtwork', track); + } + // Section: Release info const releaseInfo = sections.releaseInfo = {}; @@ -51,15 +56,8 @@ export default { contributionLinksRelation(track.artistContribs); if (track.hasUniqueCoverArt) { - relations.cover = - relation('generateCoverArtwork', track.artTags); releaseInfo.coverArtistContributionLinks = contributionLinksRelation(track.coverArtistContribs); - } else if (album.hasCoverArt) { - relations.cover = - relation('generateCoverArtwork', album.artTags); - } else { - relations.cover = null; } // Section: Listen on @@ -285,25 +283,10 @@ export default { link.slots({showContribution, showIcons}))), }); - if (data.hasUniqueCoverArt) { + if (data.hasUniqueCoverArt || data.hasAlbumCoverArt) { content.cover = relations.cover .slots({ - path: [ - 'media.trackCover', - data.albumCoverArtDirectory, - data.trackCoverArtDirectory, - data.coverArtFileExtension, - ], - }); - content.coverNeedsReveal = data.coverNeedsReveal; - } else if (data.hasAlbumCoverArt) { - content.cover = relations.cover - .slots({ - path: [ - 'media.albumCover', - data.albumCoverArtDirectory, - data.coverArtFileExtension, - ], + alt: language.$('misc.alt.trackCover'), }); content.coverNeedsReveal = data.coverNeedsReveal; } else { -- cgit 1.3.0-6-gf8a5