From 79db317f8a6d7685114f247fe9a702320c92f26d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 19 Oct 2024 21:30:05 -0300 Subject: content: generateNewsEntryNavAccent (dots) --- .../dependencies/generateNewsEntryNavAccent.js | 40 ++++++++++ src/content/dependencies/generateNewsEntryPage.js | 92 ++++++++-------------- 2 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 src/content/dependencies/generateNewsEntryNavAccent.js diff --git a/src/content/dependencies/generateNewsEntryNavAccent.js b/src/content/dependencies/generateNewsEntryNavAccent.js new file mode 100644 index 00000000..5d168e41 --- /dev/null +++ b/src/content/dependencies/generateNewsEntryNavAccent.js @@ -0,0 +1,40 @@ +export default { + contentDependencies: [ + 'generateInterpageDotSwitcher', + 'generateNextLink', + 'generatePreviousLink', + 'linkNewsEntry', + ], + + relations: (relation, previousEntry, nextEntry) => ({ + switcher: + relation('generateInterpageDotSwitcher'), + + previousLink: + relation('generatePreviousLink'), + + nextLink: + relation('generateNextLink'), + + previousEntryLink: + (previousEntry + ? relation('linkNewsEntry', previousEntry) + : null), + + nextEntryLink: + (nextEntry + ? relation('linkNewsEntry', nextEntry) + : null), + }), + + generate: (relations) => + relations.switcher.slots({ + links: [ + relations.previousLink + .slot('link', relations.previousEntryLink), + + relations.nextLink + .slot('link', relations.nextEntryLink), + ], + }), +}; diff --git a/src/content/dependencies/generateNewsEntryPage.js b/src/content/dependencies/generateNewsEntryPage.js index 2c382cfa..4abd87d1 100644 --- a/src/content/dependencies/generateNewsEntryPage.js +++ b/src/content/dependencies/generateNewsEntryPage.js @@ -3,10 +3,9 @@ import {atOffset} from '#sugar'; export default { contentDependencies: [ + 'generateNewsEntryNavAccent', 'generateNewsEntryReadAnotherLinks', 'generatePageLayout', - 'generatePreviousNextLinks', - 'linkNewsEntry', 'linkNewsIndex', 'transformContent', ], @@ -31,65 +30,46 @@ export default { return {previousEntry, nextEntry}; }, - relations(relation, query, sprawl, newsEntry) { - const relations = {}; + relations: (relation, query, sprawl, newsEntry) => ({ + layout: + relation('generatePageLayout'), - relations.layout = - relation('generatePageLayout'); + content: + relation('transformContent', newsEntry.content), - relations.content = - relation('transformContent', newsEntry.content); + newsIndexLink: + relation('linkNewsIndex'), - relations.newsIndexLink = - relation('linkNewsIndex'); + readAnotherLinks: + relation('generateNewsEntryReadAnotherLinks', + newsEntry, + query.previousEntry, + query.nextEntry), - relations.currentEntryLink = - relation('linkNewsEntry', newsEntry); + navAccent: + relation('generateNewsEntryNavAccent', + query.previousEntry, + query.nextEntry), + }), - if (query.previousEntry || query.nextEntry) { - relations.previousNextLinks = - relation('generatePreviousNextLinks'); + data: (query, sprawl, newsEntry) => ({ + name: newsEntry.name, + date: newsEntry.date, - relations.readAnotherLinks = - relation('generateNewsEntryReadAnotherLinks', - newsEntry, - query.previousEntry, - query.nextEntry); + daysSincePreviousEntry: + query.previousEntry && + Math.round((newsEntry.date - query.previousEntry.date) / 86400000), - if (query.previousEntry) { - relations.previousEntryNavLink = - relation('linkNewsEntry', query.previousEntry); - } + daysUntilNextEntry: + query.nextEntry && + Math.round((query.nextEntry.date - newsEntry.date) / 86400000), - if (query.nextEntry) { - relations.nextEntryNavLink = - relation('linkNewsEntry', query.nextEntry); - } - } + previousEntryDate: + query.previousEntry?.date, - return relations; - }, - - data(query, sprawl, newsEntry) { - return { - name: newsEntry.name, - date: newsEntry.date, - - daysSincePreviousEntry: - query.previousEntry && - Math.round((newsEntry.date - query.previousEntry.date) / 86400000), - - daysUntilNextEntry: - query.nextEntry && - Math.round((query.nextEntry.date - newsEntry.date) / 86400000), - - previousEntryDate: - query.previousEntry?.date, - - nextEntryDate: - query.nextEntry?.date, - }; - }, + nextEntryDate: + query.nextEntry?.date, + }), generate: (data, relations, {html, language}) => language.encapsulate('newsEntryPage', pageCapsule => @@ -118,13 +98,7 @@ export default { {html: relations.newsIndexLink}, { auto: 'current', - accent: - (relations.previousNextLinks - ? `(${language.formatUnitList(relations.previousNextLinks.slots({ - previousLink: relations.previousEntryNavLink ?? null, - nextLink: relations.nextEntryNavLink ?? null, - }).content)})` - : null), + accent: relations.navAccent, }, ], })), -- cgit 1.3.0-6-gf8a5