From 326ebe513e88d27c09e672ba24373fae41e0f1e1 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 1 Jul 2023 14:45:01 -0300 Subject: content: generateListingPage: listings for same target + misc. --- src/listing-spec.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) (limited to 'src/listing-spec.js') diff --git a/src/listing-spec.js b/src/listing-spec.js index c81c0866..9c1134f4 100644 --- a/src/listing-spec.js +++ b/src/listing-spec.js @@ -1,8 +1,9 @@ import {OFFICIAL_GROUP_DIRECTORY} from './util/magic-constants.js'; import { - empty, accumulateSum, + empty, + showAggregate, } from './util/sugar.js'; import { @@ -1078,34 +1079,73 @@ listingSpec.push({ ]), }); +{ + const errors = []; + + for (const listing of listingSpec) { + if (listing.seeAlso) { + const suberrors = []; + + for (let i = 0; i < listing.seeAlso.length; i++) { + const directory = listing.seeAlso[i]; + const match = listingSpec.find(listing => listing.directory === directory); + + if (match) { + listing.seeAlso[i] = match; + } else { + listing.seeAlso[i] = null; + suberrors.push(new Error(`(index: ${i}) Didn't find a listing matching ${directory}`)) + } + } + + listing.seeAlso = listing.seeAlso.filter(Boolean); + + if (!empty(suberrors)) { + errors.push(new AggregateError(suberrors, `Errors matching "see also" listings for ${listing.directory}`)); + } + } + } + + if (!empty(errors)) { + const aggregate = new AggregateError(errors, `Errors validating listings`); + showAggregate(aggregate, {showTraces: false}); + } +} + const filterListings = (directoryPrefix) => listingSpec.filter(l => l.directory.startsWith(directoryPrefix)); const listingTargetSpec = [ { - title: ({language}) => language.$('listingPage.target.album'), + stringsKey: 'album', listings: filterListings('album'), }, { - title: ({language}) => language.$('listingPage.target.artist'), + stringsKey: 'artist', listings: filterListings('artist'), }, { - title: ({language}) => language.$('listingPage.target.group'), + stringsKey: 'group', listings: filterListings('group'), }, { - title: ({language}) => language.$('listingPage.target.track'), + stringsKey: 'track', listings: filterListings('track'), }, { - title: ({language}) => language.$('listingPage.target.tag'), + stringsKey: 'tag', listings: filterListings('tag'), }, { - title: ({language}) => language.$('listingPage.target.other'), + stringsKey: 'other', listings: listingSpec.filter(l => l.groupUnderOther), }, ]; +for (const target of listingTargetSpec) { + for (const listing of target.listings) { + listing.target = target; + } +} + export {listingSpec, listingTargetSpec}; -- cgit 1.3.0-6-gf8a5