From a213861e467ec99b2a197c4c54f9034a4d9f1516 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 19 Mar 2023 17:57:27 -0300 Subject: data steps: generateAlbumInfoPage & relations implementation --- src/content/dependencies/generateAlbumInfoPage.js | 47 +++++ .../dependencies/generateAlbumInfoPageContent.js | 218 +++++++++++++++++++++ .../dependencies/generateAlbumStyleRules.js | 61 ++++++ .../dependencies/generateAlbumStylesheet.js | 61 ------ .../dependencies/generateColorStyleRules.js | 42 ++++ .../dependencies/generateContributionLinks.js | 6 + src/content/dependencies/linkArtist.js | 9 + 7 files changed, 383 insertions(+), 61 deletions(-) create mode 100644 src/content/dependencies/generateAlbumInfoPage.js create mode 100644 src/content/dependencies/generateAlbumInfoPageContent.js create mode 100644 src/content/dependencies/generateAlbumStyleRules.js delete mode 100644 src/content/dependencies/generateAlbumStylesheet.js create mode 100644 src/content/dependencies/generateColorStyleRules.js create mode 100644 src/content/dependencies/linkArtist.js (limited to 'src/content') diff --git a/src/content/dependencies/generateAlbumInfoPage.js b/src/content/dependencies/generateAlbumInfoPage.js new file mode 100644 index 00000000..8bbb320f --- /dev/null +++ b/src/content/dependencies/generateAlbumInfoPage.js @@ -0,0 +1,47 @@ +export default { + contentDependencies: [ + 'generateAlbumInfoPageContent', + 'generateAlbumSocialEmbed', + 'generateAlbumStyleRules', + 'generateColorStyleRules', + ], + + extraDependencies: [ + 'language', + ], + + relations(relation, album) { + const relations = {}; + + relations.socialEmbed = relation('generateAlbumSocialEmbed', album); + relations.albumStyleRules = relation('generateAlbumStyleRules', album); + relations.colorStyleRules = relation('generateColorStyleRules', album.color); + + return relations; + }, + + data(album) { + const data = {}; + + return data; + }, + + generate(data, relations, { + language, + }) { + const page = {}; + + page.title = language.$('albumPage.title', {album: data.name}); + + page.themeColor = data.color; + + page.styleRules = [ + relations.albumStyleRules, + relations.colorStyleRules, + ]; + + page.socialEmbed = relations.socialEmbed; + + return page; + }, +}; diff --git a/src/content/dependencies/generateAlbumInfoPageContent.js b/src/content/dependencies/generateAlbumInfoPageContent.js new file mode 100644 index 00000000..a9e51c02 --- /dev/null +++ b/src/content/dependencies/generateAlbumInfoPageContent.js @@ -0,0 +1,218 @@ +import {accumulateSum, empty} from '../../util/sugar.js'; + +export default { + contentDependencies: [ + 'generateContributionLinks', + ], + + extraDependencies: [ + 'html', + 'language', + ], + + relations(relation, album) { + const relations = {}; + + const contributionLinksRelation = contribs => + relation('generateContributionLinks', contribs, { + showContrib: true, + showIcons: true, + }) + + relations.artistLinks = + contributionLinksRelation(album.artistContribs); + + relations.coverArtistLinks = + contributionLinksRelation(album.coverArtistContribs); + + relations.wallpaperArtistLinks = + contributionLinksRelation(album.wallpaperArtistContribs); + + relations.bannerArtistLinks = + contributionLinksRelation(album.bannerArtistContribs); + + return relations; + }, + + data(album) { + const data = {}; + + data.date = album.date; + data.duration = accumulateSum(album.tracks, track => track.duration); + data.durationApproximate = album.tracks.length > 1; + + if ( + album.hasCoverArt && + album.coverArtDate && + +album.coverArtDate !== +album.date + ) { + data.coverArtDate = album.coverArtDate; + } + + return data; + }, + + generate(data, relations, { + html, + language, + }) { + const content = {}; + + content.main = { + headingMode: 'sticky', + content: [ + html.tag('p', + { + [html.onlyIfContent]: true, + [html.joinChildren]: '
', + }, + [ + !empty(relations.artistLinks) && + language.$('releaseInfo.by', { + artists: relations.artistLinks, + }), + + !empty(relations.coverArtistLinks) && + language.$('releaseInfo.coverArtBy', { + artists: relations.coverArtistLinks, + }), + + !empty(relations.wallpaperArtistLinks) && + language.$('releaseInfo.wallpaperArtBy', { + artists: relations.wallpaperArtistLinks, + }), + + !empty(relations.bannerArtistLinks) && + language.$('releaseInfo.bannerArtBy', { + artists: relations.bannerArtistLinks, + }), + + data.date && + language.$('releaseInfo.released', { + date: language.formatDate(data.date), + }), + + data.coverArtDate && + language.$('releaseInfo.artReleased', { + date: language.formatDate(data.coverArtDate), + }), + + data.duration && + language.$('releaseInfo.duration', { + duration: + language.formatDuration(data.duration, { + approximate: data.durationApproximate, + }), + }), + ]), + + /* + html.tag('p', + { + [html.onlyIfContent]: true, + [html.joinChildren]: '
', + }, + [ + hasAdditionalFiles && + generateAdditionalFilesShortcut(album.additionalFiles), + + checkGalleryPage(album) && + language.$('releaseInfo.viewGallery', { + link: link.albumGallery(album, { + text: language.$('releaseInfo.viewGallery.link'), + }), + }), + + checkCommentaryPage(album) && + language.$('releaseInfo.viewCommentary', { + link: link.albumCommentary(album, { + text: language.$('releaseInfo.viewCommentary.link'), + }), + }), + ]), + + !empty(album.urls) && + html.tag('p', + language.$('releaseInfo.listenOn', { + links: language.formatDisjunctionList( + album.urls.map(url => fancifyURL(url, {album: true})) + ), + })), + + displayTrackSections && + !empty(album.trackSections) && + html.tag('dl', + {class: 'album-group-list'}, + album.trackSections.flatMap(({ + name, + startIndex, + tracks, + }) => [ + html.tag('dt', + {class: ['content-heading']}, + language.$('trackList.section.withDuration', { + duration: language.formatDuration(getTotalDuration(tracks), { + approximate: tracks.length > 1, + }), + section: name, + })), + html.tag('dd', + html.tag(listTag, + listTag === 'ol' ? {start: startIndex + 1} : {}, + tracks.map(trackToListItem))), + ])), + + !displayTrackSections && + !empty(album.tracks) && + html.tag(listTag, + album.tracks.map(trackToListItem)), + + html.tag('p', + { + [html.onlyIfContent]: true, + [html.joinChildren]: '
', + }, + [ + album.dateAddedToWiki && + language.$('releaseInfo.addedToWiki', { + date: language.formatDate( + album.dateAddedToWiki + ), + }) + ]), + + ...html.fragment( + hasAdditionalFiles && [ + generateContentHeading({ + id: 'additional-files', + title: language.$('releaseInfo.additionalFiles.heading', { + additionalFiles: language.countAdditionalFiles(numAdditionalFiles, { + unit: true, + }), + }), + }), + + generateAlbumAdditionalFilesList(album, album.additionalFiles, { + generateAdditionalFilesList, + getSizeOfAdditionalFile, + link, + urls, + }), + ]), + + ...html.fragment( + album.commentary && [ + generateContentHeading({ + id: 'artist-commentary', + title: language.$('releaseInfo.artistCommentary'), + }), + + html.tag('blockquote', transformMultiline(album.commentary)), + ]) + */ + ] + }; + + return content; + }, +}; diff --git a/src/content/dependencies/generateAlbumStyleRules.js b/src/content/dependencies/generateAlbumStyleRules.js new file mode 100644 index 00000000..c9547836 --- /dev/null +++ b/src/content/dependencies/generateAlbumStyleRules.js @@ -0,0 +1,61 @@ +import {empty} from '../../util/sugar.js'; + +export default { + extraDependencies: [ + 'to', + ], + + data(album) { + 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; + } + + if (data.hasBanner) { + data.hasBannerStyle = !!album.bannerStyle; + data.bannerStyle = album.bannerStyle; + } + + 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 bannerPart = + (data.hasBannerStyle + ? [ + `#banner img {`, + ...data.bannerStyle + .split('\n') + .map(line => ` ${line}`), + `}`, + ] + : []); + + return [ + ...wallpaperPart, + ...bannerPart, + ] + .filter(Boolean) + .join('\n'); + }, +}; diff --git a/src/content/dependencies/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStylesheet.js deleted file mode 100644 index c9547836..00000000 --- a/src/content/dependencies/generateAlbumStylesheet.js +++ /dev/null @@ -1,61 +0,0 @@ -import {empty} from '../../util/sugar.js'; - -export default { - extraDependencies: [ - 'to', - ], - - data(album) { - 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; - } - - if (data.hasBanner) { - data.hasBannerStyle = !!album.bannerStyle; - data.bannerStyle = album.bannerStyle; - } - - 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 bannerPart = - (data.hasBannerStyle - ? [ - `#banner img {`, - ...data.bannerStyle - .split('\n') - .map(line => ` ${line}`), - `}`, - ] - : []); - - return [ - ...wallpaperPart, - ...bannerPart, - ] - .filter(Boolean) - .join('\n'); - }, -}; diff --git a/src/content/dependencies/generateColorStyleRules.js b/src/content/dependencies/generateColorStyleRules.js new file mode 100644 index 00000000..02c3380e --- /dev/null +++ b/src/content/dependencies/generateColorStyleRules.js @@ -0,0 +1,42 @@ +export default { + extraDependencies: [ + 'getColors', + ], + + data(color) { + return {color}; + }, + + generate(data, { + getColors, + }) { + if (!color) return ''; + + const { + primary, + dark, + dim, + dimGhost, + bg, + bgBlack, + shadow, + } = getColors(data.color); + + const variables = [ + `--primary-color: ${primary}`, + `--dark-color: ${dark}`, + `--dim-color: ${dim}`, + `--dim-ghost-color: ${dimGhost}`, + `--bg-color: ${bg}`, + `--bg-black-color: ${bgBlack}`, + `--shadow-color: ${shadow}`, + ...additionalVariables, + ]; + + return [ + `:root {`, + ...variables.map((line) => ` ${line};`), + `}`, + ].join('\n'); + }, +}; diff --git a/src/content/dependencies/generateContributionLinks.js b/src/content/dependencies/generateContributionLinks.js index 74695796..a79c8234 100644 --- a/src/content/dependencies/generateContributionLinks.js +++ b/src/content/dependencies/generateContributionLinks.js @@ -5,6 +5,12 @@ export default { 'linkArtist', ], + extraDependencies: [ + 'html', + 'iconifyURL', + 'language', + ], + relations(relation, contributions) { const relations = {}; diff --git a/src/content/dependencies/linkArtist.js b/src/content/dependencies/linkArtist.js new file mode 100644 index 00000000..396eca41 --- /dev/null +++ b/src/content/dependencies/linkArtist.js @@ -0,0 +1,9 @@ +export default { + data(artist) { + return {directory: artist.directory}; + }, + + generate(data) { + return `(stub artist link: "${data.directory}")`; + }, +}; -- cgit 1.3.0-6-gf8a5