From 0ab01d4bdced28527007c2f26d13610f1730906c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 4 Jun 2021 15:56:59 -0300 Subject: module-ify listing pages --- src/page/index.js | 1 + src/page/listing.js | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/page/listing.js (limited to 'src/page') diff --git a/src/page/index.js b/src/page/index.js index c5e10631..aa115c9b 100644 --- a/src/page/index.js +++ b/src/page/index.js @@ -44,6 +44,7 @@ export * as artist from './artist.js'; export * as artistAlias from './artist-alias.js'; export * as group from './group.js'; export * as homepage from './homepage.js'; +export * as listing from './listing.js'; export * as static from './static.js'; export * as news from './news.js'; export * as track from './track.js'; diff --git a/src/page/listing.js b/src/page/listing.js new file mode 100644 index 00000000..b0766b28 --- /dev/null +++ b/src/page/listing.js @@ -0,0 +1,157 @@ +// Listing page specification. +// +// The targets here are a bit different than for most pages: rather than data +// objects loaded from text files in the wiki data directory, they're hard- +// coded specifications, with various JS functions for processing wiki data +// and turning it into user-readable HTML listings. +// +// Individual listing specs are described in src/listing-spec.js, but are +// provided via wikiData like other (normal) data objects. + +// Imports + +import fixWS from 'fix-whitespace'; + +import * as html from '../util/html.js'; + +import { + UNRELEASED_TRACKS_DIRECTORY +} from '../util/magic-constants.js'; + +import { + getTotalDuration +} from '../util/wiki-data.js'; + +// Page exports + +export function condition({wikiData}) { + return wikiData.wikiInfo.features.listings; +} + +export function targets({wikiData}) { + return wikiData.listingSpec; +} + +export function write(listing, {wikiData}) { + if (listing.condition && !listing.condition({wikiData})) { + return null; + } + + const { wikiInfo } = wikiData; + + const data = (listing.data + ? listing.data({wikiData}) + : null); + + const page = { + type: 'page', + path: ['listing', listing.directory], + page: ({ + link, + strings + }) => ({ + title: listing.title({strings}), + + main: { + content: fixWS` +

${listing.title({strings})}

+ ${listing.html && (listing.data + ? listing.html(data, {link, strings}) + : listing.html({link, strings}))} + ${listing.row && fixWS` + + `} + ` + }, + + sidebarLeft: { + content: generateSidebarForListings(listing, {link, strings, wikiData}) + }, + + nav: { + links: [ + {toHome: true}, + { + path: ['localized.listingIndex'], + title: strings('listingIndex.title') + }, + {toCurrentPage: true} + ] + } + }) + }; + + return [page]; +} + +export function writeTargetless({wikiData}) { + const { albumData, trackData, wikiInfo } = wikiData; + + const releasedTracks = trackData.filter(track => track.album.directory !== UNRELEASED_TRACKS_DIRECTORY); + const releasedAlbums = albumData.filter(album => album.directory !== UNRELEASED_TRACKS_DIRECTORY); + const duration = getTotalDuration(releasedTracks); + + const page = { + type: 'page', + path: ['listingIndex'], + page: ({ + strings, + link + }) => ({ + title: strings('listingIndex.title'), + + main: { + content: fixWS` +

${strings('listingIndex.title')}

+

${strings('listingIndex.infoLine', { + wiki: wikiInfo.name, + tracks: `${strings.count.tracks(releasedTracks.length, {unit: true})}`, + albums: `${strings.count.albums(releasedAlbums.length, {unit: true})}`, + duration: `${strings.count.duration(duration, {approximate: true, unit: true})}` + })}

+
+

${strings('listingIndex.exploreList')}

+ ${generateLinkIndexForListings(null, {link, strings, wikiData})} + ` + }, + + sidebarLeft: { + content: generateSidebarForListings(null, {link, strings, wikiData}) + }, + + nav: {simple: true} + }) + }; + + return [page]; +}; + +// Utility functions + +function generateSidebarForListings(currentListing, {link, strings, wikiData}) { + return fixWS` +

${link.listingIndex('', {text: strings('listingIndex.title')})}

+ ${generateLinkIndexForListings(currentListing, {link, strings, wikiData})} + `; +} + +function generateLinkIndexForListings(currentListing, {link, strings, wikiData}) { + const { listingSpec } = wikiData; + + return fixWS` + + `; +} -- cgit 1.3.0-6-gf8a5