« get me outta code hell

content: generateNewsEntryNavAccent (dots) - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-10-19 21:30:05 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-11-02 22:25:46 -0300
commit79db317f8a6d7685114f247fe9a702320c92f26d (patch)
tree9e0565749bb5f3995fdf5e49c4f6a253edb61ed8 /src
parent047c98a6fd5f488c1d5957add8e0908c24079459 (diff)
content: generateNewsEntryNavAccent (dots)
Diffstat (limited to 'src')
-rw-r--r--src/content/dependencies/generateNewsEntryNavAccent.js40
-rw-r--r--src/content/dependencies/generateNewsEntryPage.js92
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,
           },
         ],
       })),