diff options
-rw-r--r-- | src/content/dependencies/generateNewsEntryNavAccent.js | 40 | ||||
-rw-r--r-- | src/content/dependencies/generateNewsEntryPage.js | 92 |
2 files changed, 73 insertions, 59 deletions
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, }, ], })), |