From 3d0ac39a533f41cc2ff43f1a77dbe31c9cdf1fb5 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 14 Aug 2024 12:36:08 -0300 Subject: content: generateFlashNavAccent: update internals + use dots --- src/content/dependencies/generateFlashNavAccent.js | 81 ++++++++++------------ 1 file changed, 37 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/content/dependencies/generateFlashNavAccent.js b/src/content/dependencies/generateFlashNavAccent.js index 55e056dc..0f5d2d6b 100644 --- a/src/content/dependencies/generateFlashNavAccent.js +++ b/src/content/dependencies/generateFlashNavAccent.js @@ -1,16 +1,17 @@ -import {atOffset, empty} from '#sugar'; +import {atOffset} from '#sugar'; export default { contentDependencies: [ - 'generatePreviousNextLinks', + 'generateInterpageDotSwitcher', + 'generateNextLink', + 'generatePreviousLink', 'linkFlash', ], extraDependencies: ['html', 'language', 'wikiData'], - sprawl({flashActData}) { - return {flashActData}; - }, + sprawl: ({flashActData}) => + ({flashActData}), query(sprawl, flash) { // Don't sort chronologically here. The previous/next buttons should match @@ -31,43 +32,35 @@ export default { return {previousFlash, nextFlash}; }, - relations(relation, query) { - const relations = {}; - - if (query.previousFlash || query.nextFlash) { - relations.previousNextLinks = - relation('generatePreviousNextLinks'); - - relations.previousFlashLink = - (query.previousFlash - ? relation('linkFlash', query.previousFlash) - : null); - - relations.nextFlashLink = - (query.nextFlash - ? relation('linkFlash', query.nextFlash) - : null); - } - - return relations; - }, - - generate(relations, {html, language}) { - const {content: previousNextLinks = []} = - relations.previousNextLinks && - relations.previousNextLinks.slots({ - previousLink: relations.previousFlashLink, - nextLink: relations.nextFlashLink, - }); - - const allLinks = [ - ...previousNextLinks, - ].filter(Boolean); - - if (empty(allLinks)) { - return html.blank(); - } - - return `(${language.formatUnitList(allLinks)})`; - }, + relations: (relation, query) => ({ + switcher: + relation('generateInterpageDotSwitcher'), + + previousLink: + relation('generatePreviousLink'), + + nextLink: + relation('generateNextLink'), + + previousFlashLink: + (query.previousFlash + ? relation('linkFlash', query.previousFlash) + : null), + + nextFlashLink: + (query.nextFlash + ? relation('linkFlash', query.nextFlash) + : null), + }), + + generate: (relations) => + relations.switcher.slots({ + links: [ + relations.previousLink + .slot('link', relations.previousFlashLink), + + relations.nextLink + .slot('link', relations.nextFlashLink), + ], + }), }; -- cgit 1.3.0-6-gf8a5