« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateNewsEntryPage.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateNewsEntryPage.js')
-rw-r--r--src/content/dependencies/generateNewsEntryPage.js92
1 files changed, 33 insertions, 59 deletions
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,
           },
         ],
       })),