From 424cb392d3a4fc2f7b47b68de30378fc5abf1321 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 24 Sep 2023 15:40:20 -0300 Subject: content: generateAlbumStyleRules: provide album & track directory --- .../dependencies/generateAlbumCommentaryPage.js | 2 +- .../dependencies/generateAlbumGalleryPage.js | 2 +- src/content/dependencies/generateAlbumInfoPage.js | 2 +- .../dependencies/generateAlbumStyleRules.js | 72 +++++++++++++--------- src/content/dependencies/generateTrackInfoPage.js | 2 +- 5 files changed, 46 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/content/dependencies/generateAlbumCommentaryPage.js b/src/content/dependencies/generateAlbumCommentaryPage.js index de619251..5979ed3f 100644 --- a/src/content/dependencies/generateAlbumCommentaryPage.js +++ b/src/content/dependencies/generateAlbumCommentaryPage.js @@ -21,7 +21,7 @@ export default { relation('generatePageLayout'); relations.albumStyleRules = - relation('generateAlbumStyleRules', album); + relation('generateAlbumStyleRules', album, null); relations.albumLink = relation('linkAlbum', album); diff --git a/src/content/dependencies/generateAlbumGalleryPage.js b/src/content/dependencies/generateAlbumGalleryPage.js index 68b56bd9..b98abc46 100644 --- a/src/content/dependencies/generateAlbumGalleryPage.js +++ b/src/content/dependencies/generateAlbumGalleryPage.js @@ -51,7 +51,7 @@ export default { relation('generatePageLayout'); relations.albumStyleRules = - relation('generateAlbumStyleRules', album); + relation('generateAlbumStyleRules', album, null); relations.albumLink = relation('linkAlbum', album); diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js index ce17ab21..5c4344b0 100644 --- a/src/content/dependencies/generateAlbumInfoPage.js +++ b/src/content/dependencies/generateAlbumInfoPage.js @@ -37,7 +37,7 @@ export default { relation('generatePageLayout'); relations.albumStyleRules = - relation('generateAlbumStyleRules', album); + relation('generateAlbumStyleRules', album, null); relations.socialEmbed = relation('generateAlbumSocialEmbed', album); diff --git a/src/content/dependencies/generateAlbumStyleRules.js b/src/content/dependencies/generateAlbumStyleRules.js index 1acaea17..9269ae83 100644 --- a/src/content/dependencies/generateAlbumStyleRules.js +++ b/src/content/dependencies/generateAlbumStyleRules.js @@ -3,14 +3,13 @@ import {empty} from '#sugar'; export default { extraDependencies: ['to'], - data(album) { + data(album, track) { const data = {}; data.hasWallpaper = !empty(album.wallpaperArtistContribs); data.hasBanner = !empty(album.bannerArtistContribs); if (data.hasWallpaper) { - data.hasWallpaperStyle = !!album.wallpaperStyle; data.wallpaperPath = ['media.albumWallpaper', album.directory, album.wallpaperFileExtension]; data.wallpaperStyle = album.wallpaperStyle; } @@ -20,40 +19,53 @@ export default { data.bannerStyle = album.bannerStyle; } + data.albumDirectory = album.directory; + + if (track) { + data.trackDirectory = track.directory; + } + return data; }, generate(data, {to}) { - const wallpaperPart = - (data.hasWallpaper - ? [ - `body::before {`, - ` background-image: url("${to(...data.wallpaperPath)}");`, - ...(data.hasWallpaperStyle - ? data.wallpaperStyle - .split('\n') - .map(line => ` ${line}`) - : []), - `}`, - ] - : []); + const indent = parts => + (parts ?? []) + .filter(Boolean) + .join('\n') + .split('\n') + .map(line => ' '.repeat(4) + line) + .join('\n'); - const bannerPart = - (data.hasBannerStyle - ? [ - `#banner img {`, - ...data.bannerStyle - .split('\n') - .map(line => ` ${line}`), - `}`, - ] + const rule = (selector, parts) => + (!empty(parts.filter(Boolean)) + ? [`${selector} {`, indent(parts), `}`] : []); - return [ - ...wallpaperPart, - ...bannerPart, - ] - .filter(Boolean) - .join('\n'); + const wallpaperRule = + data.hasWallpaper && + rule(`body::before`, [ + `background-image: url("${to(...data.wallpaperPath)}");`, + data.wallpaperStyle, + ]); + + const bannerRule = + data.hasBanner && + rule(`#banner img`, [ + data.bannerStyle, + ]); + + const dataRule = + rule(`:root`, [ + data.albumDirectory && + `--album-directory: ${data.albumDirectory};`, + data.trackDirectory && + `--track-directory: ${data.trackDirectory};`, + ]); + + return ( + [...wallpaperRule, ...bannerRule, ...dataRule] + .filter(Boolean) + .join('\n')); }, }; diff --git a/src/content/dependencies/generateTrackInfoPage.js b/src/content/dependencies/generateTrackInfoPage.js index 334c5422..c20c0d08 100644 --- a/src/content/dependencies/generateTrackInfoPage.js +++ b/src/content/dependencies/generateTrackInfoPage.js @@ -44,7 +44,7 @@ export default { relation('generatePageLayout'); relations.albumStyleRules = - relation('generateAlbumStyleRules', track.album); + relation('generateAlbumStyleRules', track.album, track); relations.socialEmbed = relation('generateTrackSocialEmbed', track); -- cgit 1.3.0-6-gf8a5 From 8ed9240b56d61be97a5cc1da7c9fcb179bb58a93 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 26 Sep 2023 11:32:12 -0300 Subject: content: generateAlbumStyleRules: oops --- src/content/dependencies/generateAlbumStyleRules.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/content/dependencies/generateAlbumStyleRules.js b/src/content/dependencies/generateAlbumStyleRules.js index 9269ae83..c5acf374 100644 --- a/src/content/dependencies/generateAlbumStyleRules.js +++ b/src/content/dependencies/generateAlbumStyleRules.js @@ -64,8 +64,9 @@ export default { ]); return ( - [...wallpaperRule, ...bannerRule, ...dataRule] + [wallpaperRule, bannerRule, dataRule] .filter(Boolean) + .flat() .join('\n')); }, }; -- cgit 1.3.0-6-gf8a5