diff options
-rw-r--r-- | src/content-function.js | 45 | ||||
-rw-r--r-- | src/content/dependencies/generateAlbumInfoPage.js | 47 | ||||
-rw-r--r-- | src/content/dependencies/generateAlbumInfoPageContent.js | 218 | ||||
-rw-r--r-- | src/content/dependencies/generateAlbumStyleRules.js (renamed from src/content/dependencies/generateAlbumStylesheet.js) | 0 | ||||
-rw-r--r-- | src/content/dependencies/generateColorStyleRules.js | 42 | ||||
-rw-r--r-- | src/content/dependencies/generateContributionLinks.js | 6 | ||||
-rw-r--r-- | src/content/dependencies/linkArtist.js | 9 | ||||
-rw-r--r-- | src/misc-templates.js | 39 | ||||
-rw-r--r-- | src/page/album.js | 183 |
9 files changed, 354 insertions, 235 deletions
diff --git a/src/content-function.js b/src/content-function.js index 654a294c..93bef6bd 100644 --- a/src/content-function.js +++ b/src/content-function.js @@ -6,10 +6,12 @@ export default function contentFunction({ data, generate, + relations, }) { return expectDependencies({ data, generate, + relations, expectedContentDependencyKeys: contentDependencies, expectedExtraDependencyKeys: extraDependencies, @@ -20,8 +22,9 @@ export default function contentFunction({ contentFunction.identifyingSymbol = Symbol(`Is a content function?`); export function expectDependencies({ - generate, data, + generate, + relations, expectedContentDependencyKeys, expectedExtraDependencyKeys, @@ -59,8 +62,12 @@ export function expectDependencies({ } if (empty(missingContentDependencyKeys) && empty(missingExtraDependencyKeys)) { - wrappedGenerate ??= function(data) { - return generate(data, fulfilledDependencies); + wrappedGenerate ??= function(data, relations) { + if (relations) { + return generate(data, relations, fulfilledDependencies); + } else { + return generate(data, fulfilledDependencies); + } }; annotateFunction(wrappedGenerate, {name: generate, trait: 'fulfilled'}); @@ -71,15 +78,19 @@ export function expectDependencies({ }; } - wrappedGenerate ??= function() { - throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.concat(missingExtraDependencyKeys).join(', ')}`); - }; + if (!wrappedGenerate) { + wrappedGenerate = function() { + throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.concat(missingExtraDependencyKeys).join(', ')}`); + }; + + annotateFunction(wrappedGenerate, {name: generate, trait: 'unfulfilled'}); + wrappedGenerate.fulfilled = false; + } - annotateFunction(wrappedGenerate, {name: generate, trait: 'unfulfilled'}); - wrappedGenerate.fulfilled ??= false; wrappedGenerate[contentFunction.identifyingSymbol] = true; if (empty(missingContentDependencyKeys)) { + /* const dataDependencies = {}; for (const key of expectedContentDependencyKeys) { @@ -97,18 +108,26 @@ export function expectDependencies({ }; annotateFunction(wrappedGenerate.data, {name: data, trait: 'fulfilled'}); + */ + + wrappedGenerate.data = data; } - wrappedGenerate.data ??= function() { - throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`); - }; + if (!wrappedGenerate.data) { + wrappedGenerate.data = function() { + throw new Error(`Dependencies still needed: ${missingContentDependencyKeys.join(', ')}`); + }; - annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'}); + annotateFunction(wrappedGenerate.data, {name: data, trait: 'unfulfilled'}); + } + + wrappedGenerate.relations = relations; wrappedGenerate.fulfill ??= function fulfill(dependencies) { return expectDependencies({ - generate, data, + generate, + relations, expectedContentDependencyKeys, expectedExtraDependencyKeys, 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]: '<br>', + }, + [ + !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]: '<br>', + }, + [ + 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]: '<br>', + }, + [ + 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/generateAlbumStylesheet.js b/src/content/dependencies/generateAlbumStyleRules.js index c9547836..c9547836 100644 --- a/src/content/dependencies/generateAlbumStylesheet.js +++ b/src/content/dependencies/generateAlbumStyleRules.js 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}")`; + }, +}; diff --git a/src/misc-templates.js b/src/misc-templates.js index 3e6948c0..afcb9c3b 100644 --- a/src/misc-templates.js +++ b/src/misc-templates.js @@ -227,45 +227,6 @@ function unbound_generateCoverLink({ ]); } -// CSS & color shenanigans - -function unbound_getThemeString(color, { - getColors, - - additionalVariables = [], -} = {}) { - if (!color) return ''; - - const { - primary, - dark, - dim, - dimGhost, - bg, - bgBlack, - shadow, - } = getColors(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, - ].filter(Boolean); - - if (!variables.length) return ''; - - return [ - `:root {`, - ...variables.map((line) => ` ${line};`), - `}` - ].join('\n'); -} - // Divided track lists function unbound_generateTrackListDividedByGroups(tracks, { diff --git a/src/page/album.js b/src/page/album.js index 9e1d8c9f..eeb6dc7c 100644 --- a/src/page/album.js +++ b/src/page/album.js @@ -16,9 +16,6 @@ import { u_generateAlbumStylesheet, } from '../misc-templates.js'; -import u_link from '../util/link.js'; -import contentFunction from '../util/content-function.js'; - export const description = `per-album info & track artwork gallery pages`; export function targets({wikiData}) { @@ -126,26 +123,6 @@ export const dataSteps = { }); void generateTrackListItem; - - return { - title: language.$('albumPage.title', {album: data.name}), - stylesheet: getAlbumStylesheet(data.stylesheetData), - - themeColor: data.color, - theme: - getThemeString(data.color, { - additionalVariables: [ - `--album-directory: ${data.directory}`, - ], - }), - - socialEmbed: generateAlbumSocialEmbed(data.socialEmbedData, { - absoluteTo, - getAlbumCover, - getSocialEmbedDescription, - to, - }), - }; }, }, }; @@ -175,166 +152,6 @@ const infoPage = { headingMode: 'sticky', content: [ - html.tag('p', - { - [html.onlyIfContent]: true, - [html.joinChildren]: '<br>', - }, - [ - !empty(album.artistContribs) && - language.$('releaseInfo.by', { - artists: getArtistString(album.artistContribs, { - showContrib: true, - showIcons: true, - }), - }), - - !empty(album.coverArtistContribs) && - language.$('releaseInfo.coverArtBy', { - artists: getArtistString(album.coverArtistContribs, { - showContrib: true, - showIcons: true, - }), - }), - - !empty(album.wallpaperArtistContribs) && - language.$('releaseInfo.wallpaperArtBy', { - artists: getArtistString(album.wallpaperArtistContribs, { - showContrib: true, - showIcons: true, - }), - }), - - !empty(album.bannerArtistContribs) && - language.$('releaseInfo.bannerArtBy', { - artists: getArtistString(album.bannerArtistContribs, { - showContrib: true, - showIcons: true, - }), - }), - - album.date && - language.$('releaseInfo.released', { - date: language.formatDate(album.date), - }), - - album.hasCoverArt && - album.coverArtDate && - +album.coverArtDate !== +album.date && - language.$('releaseInfo.artReleased', { - date: language.formatDate(album.coverArtDate), - }), - - albumDuration > 0 && - language.$('releaseInfo.duration', { - duration: language.formatDuration(albumDuration, { - approximate: album.tracks.length > 1, - }), - }), - ]), - - html.tag('p', - { - [html.onlyIfContent]: true, - [html.joinChildren]: '<br>', - }, - [ - 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]: '<br>', - }, - [ - 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)), - ]), ], }, |