From c60b3722f23d88680c7ceee72c32ef87545752ea Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 4 Jun 2021 16:21:58 -0300 Subject: module-ify album commentary pages --- src/page/album-commentary.js | 146 +++++++++++++++++++++++++++++++++++++++++++ src/page/index.js | 1 + 2 files changed, 147 insertions(+) create mode 100644 src/page/album-commentary.js (limited to 'src/page') diff --git a/src/page/album-commentary.js b/src/page/album-commentary.js new file mode 100644 index 0000000..77ca3ef --- /dev/null +++ b/src/page/album-commentary.js @@ -0,0 +1,146 @@ +// Album commentary page and index specifications. + +// Imports + +import fixWS from 'fix-whitespace'; + +import { + getLinkThemeString, + getThemeString +} from '../util/colors.js'; + +import { + filterAlbumsByCommentary +} from '../util/wiki-data.js'; + +// Page exports + +export function condition({wikiData}) { + return filterAlbumsByCommentary(wikiData.albumData).length; +} + +export function targets({wikiData}) { + return filterAlbumsByCommentary(wikiData.albumData); +} + +export function write(album, {wikiData}) { + const { wikiInfo } = wikiData; + + const entries = [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary); + const words = entries.join(' ').split(' ').length; + + const page = { + type: 'page', + path: ['albumCommentary', album.directory], + page: ({ + getAlbumStylesheet, + link, + strings, + to, + transformMultiline + }) => ({ + title: strings('albumCommentaryPage.title', {album: album.name}), + stylesheet: getAlbumStylesheet(album), + theme: getThemeString(album.color), + + main: { + content: fixWS` +
+

${strings('albumCommentaryPage.title', { + album: link.album(album) + })}

+

${strings('albumCommentaryPage.infoLine', { + words: `${strings.count.words(words, {unit: true})}`, + entries: `${strings.count.commentaryEntries(entries.length, {unit: true})}` + })}

+ ${album.commentary && fixWS` +

${strings('albumCommentaryPage.entry.title.albumCommentary')}

+
+ ${transformMultiline(album.commentary)} +
+ `} + ${album.tracks.filter(t => t.commentary).map(track => fixWS` +

${strings('albumCommentaryPage.entry.title.trackCommentary', { + track: link.track(track) + })}

+
+ ${transformMultiline(track.commentary)} +
+ `).join('\n')} +
+ ` + }, + + nav: { + links: [ + {toHome: true}, + { + path: ['localized.commentaryIndex'], + title: strings('commentaryIndex.title') + }, + { + html: strings('albumCommentaryPage.nav.album', { + album: link.albumCommentary(album, {class: 'current'}) + }) + } + ] + } + }) + }; + + return [page]; +} + +export function writeTargetless({wikiData}) { + const data = filterAlbumsByCommentary(wikiData.albumData) + .map(album => ({ + album, + entries: [album, ...album.tracks].filter(x => x.commentary).map(x => x.commentary) + })) + .map(({ album, entries }) => ({ + album, entries, + words: entries.join(' ').split(' ').length + })); + + const totalEntries = data.reduce((acc, {entries}) => acc + entries.length, 0); + const totalWords = data.reduce((acc, {words}) => acc + words, 0); + + const page = { + type: 'page', + path: ['commentaryIndex'], + page: ({ + link, + strings + }) => ({ + title: strings('commentaryIndex.title'), + + main: { + content: fixWS` +
+

${strings('commentaryIndex.title')}

+

${strings('commentaryIndex.infoLine', { + words: `${strings.count.words(totalWords, {unit: true})}`, + entries: `${strings.count.commentaryEntries(totalEntries, {unit: true})}` + })}

+

${strings('commentaryIndex.albumList.title')}

+ +
+ ` + }, + + nav: {simple: true} + }) + }; + + return [page]; +} diff --git a/src/page/index.js b/src/page/index.js index 4ef5797..101a168 100644 --- a/src/page/index.js +++ b/src/page/index.js @@ -40,6 +40,7 @@ // pertain only to site page generation. export * as album from './album.js'; +export * as albumCommentary from './album-commentary.js'; export * as artist from './artist.js'; export * as artistAlias from './artist-alias.js'; export * as flash from './flash.js'; -- cgit 1.3.0-6-gf8a5