diff options
-rw-r--r-- | src/content/dependencies/generateFlashNavAccent.js | 81 |
1 files changed, 37 insertions, 44 deletions
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), + ], + }), }; |