« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js2
-rw-r--r--src/content/dependencies/generateFlashActNavAccent.js13
-rw-r--r--src/content/dependencies/generateFlashNavAccent.js13
-rw-r--r--src/content/dependencies/generateGroupSecondaryNav.js10
-rw-r--r--src/content/dependencies/generateNewsEntryPage.js9
-rw-r--r--src/data/composite/data/withSortedList.js2
-rw-r--r--src/data/yaml.js11
-rw-r--r--src/util/replacer.js2
8 files changed, 23 insertions, 39 deletions
diff --git a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
index 392b2782..799e8509 100644
--- a/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
+++ b/src/content/dependencies/generateArtistInfoPageFlashesChunkedList.js
@@ -71,7 +71,7 @@ export default {
         query.chunks.map(({chunk}) => chunk[0].flash.date ?? null),
 
       lastDates:
-        query.chunks.map(({chunk}) => chunk[chunk.length - 1].flash.date ?? null),
+        query.chunks.map(({chunk}) => chunk.at(-1).flash.date ?? null),
 
       itemContributions:
         query.chunks.map(({chunk}) =>
diff --git a/src/content/dependencies/generateFlashActNavAccent.js b/src/content/dependencies/generateFlashActNavAccent.js
index 98504385..424948f9 100644
--- a/src/content/dependencies/generateFlashActNavAccent.js
+++ b/src/content/dependencies/generateFlashActNavAccent.js
@@ -1,4 +1,4 @@
-import {empty} from '#sugar';
+import {atOffset, empty} from '#sugar';
 
 export default {
   contentDependencies: [
@@ -17,17 +17,14 @@ export default {
     const flashActs =
       sprawl.flashActData;
 
-    const index = flashActs.indexOf(flashAct);
+    const index =
+      flashActs.indexOf(flashAct);
 
     const previousFlashAct =
-      (index > 0
-        ? flashActs[index - 1]
-        : null);
+      atOffset(flashActs, index, -1);
 
     const nextFlashAct =
-      (index < flashActs.length - 1
-        ? flashActs[index + 1]
-        : null);
+      atOffset(flashActs, index, +1);
 
     return {previousFlashAct, nextFlashAct};
   },
diff --git a/src/content/dependencies/generateFlashNavAccent.js b/src/content/dependencies/generateFlashNavAccent.js
index 57196d06..55e056dc 100644
--- a/src/content/dependencies/generateFlashNavAccent.js
+++ b/src/content/dependencies/generateFlashNavAccent.js
@@ -1,4 +1,4 @@
-import {empty} from '#sugar';
+import {atOffset, empty} from '#sugar';
 
 export default {
   contentDependencies: [
@@ -19,17 +19,14 @@ export default {
       sprawl.flashActData
         .flatMap(act => act.flashes);
 
-    const index = flashes.indexOf(flash);
+    const index =
+      flashes.indexOf(flash);
 
     const previousFlash =
-      (index > 0
-        ? flashes[index - 1]
-        : null);
+      atOffset(flashes, index, -1);
 
     const nextFlash =
-      (index < flashes.length - 1
-        ? flashes[index + 1]
-        : null);
+      atOffset(flashes, index, +1);
 
     return {previousFlash, nextFlash};
   },
diff --git a/src/content/dependencies/generateGroupSecondaryNav.js b/src/content/dependencies/generateGroupSecondaryNav.js
index c649e300..e9c7004d 100644
--- a/src/content/dependencies/generateGroupSecondaryNav.js
+++ b/src/content/dependencies/generateGroupSecondaryNav.js
@@ -1,3 +1,5 @@
+import {atOffset} from '#sugar';
+
 export default {
   contentDependencies: [
     'generateColorStyleAttribute',
@@ -23,14 +25,10 @@ export default {
 
     return {
       previousGroup:
-        (index > 0
-          ? groups[index - 1]
-          : null),
+        atOffset(groups, index, -1),
 
       nextGroup:
-        (index < groups.length - 1
-          ? groups[index + 1]
-          : null),
+        atOffset(groups, index, +1),
     };
   },
 
diff --git a/src/content/dependencies/generateNewsEntryPage.js b/src/content/dependencies/generateNewsEntryPage.js
index fbd4f609..fa4d68a8 100644
--- a/src/content/dependencies/generateNewsEntryPage.js
+++ b/src/content/dependencies/generateNewsEntryPage.js
@@ -1,3 +1,4 @@
+import {atOffset} from '#sugar';
 import {sortChronologically} from '#wiki-data';
 
 export default {
@@ -22,14 +23,10 @@ export default {
     const index = entries.indexOf(newsEntry);
 
     const previousEntry =
-      (index > 0
-        ? entries[index - 1]
-        : null);
+      atOffset(entries, index, -1);
 
     const nextEntry =
-      (index < entries.length - 1
-        ? entries[index + 1]
-        : null);
+      atOffset(entries, index, +1);
 
     return {previousEntry, nextEntry};
   },
diff --git a/src/data/composite/data/withSortedList.js b/src/data/composite/data/withSortedList.js
index 882907f5..4ab0dfb1 100644
--- a/src/data/composite/data/withSortedList.js
+++ b/src/data/composite/data/withSortedList.js
@@ -102,7 +102,7 @@ export default templateCompositeFrom({
               if (empty(accumulator)) {
                 accumulator.push(0);
               } else {
-                const last = accumulator[accumulator.length - 1];
+                const last = accumulator.at(-1);
                 if (collapseEqual) {
                   accumulator.push(last);
                 } else {
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 2137f994..5a4e87e3 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -17,6 +17,7 @@ import T, {Thing} from '#things';
 
 import {
   annotateErrorWithFile,
+  atOffset,
   conditionallySuppressError,
   decorateErrorWithIndex,
   decorateErrorWithAnnotation,
@@ -1237,14 +1238,8 @@ export async function loadAndProcessDataDocuments({dataPath}) {
                   start,
                   end,
                   count: end - start + 1,
-                  previous:
-                    (start > 0
-                      ? documents[start - 1]
-                      : null),
-                  next:
-                    (end < documents.length - 1
-                      ? documents[end + 1]
-                      : null),
+                  previous: atOffset(documents, start, -1),
+                  next: atOffset(documents, end, +1),
                 }));
 
             for (const {start, end, count, previous, next} of blankIndexRangeInfo) {
diff --git a/src/util/replacer.js b/src/util/replacer.js
index a2df2c3f..d9fd8923 100644
--- a/src/util/replacer.js
+++ b/src/util/replacer.js
@@ -287,7 +287,7 @@ export function postprocessImages(inputNodes) {
 
   let atStartOfLine = true;
 
-  const lastNode = inputNodes[inputNodes.length - 1];
+  const lastNode = inputNodes.at(-1);
 
   for (const node of inputNodes) {
     if (node.type === 'tag') {