« get me outta code hell

integrate "latest first" into sortChronologically - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-11-27 01:04:37 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-11-27 01:04:37 -0400
commitdd4e642b381f1af8f235a1eff4eb886b12be31ad (patch)
tree1cb16f49b5dce3a4cf5aa2a7b9a7f9ab461f98b5 /src/util
parentb83797b525d70072c02aa0b201a4863df2447f48 (diff)
integrate "latest first" into sortChronologically
Diffstat (limited to 'src/util')
-rw-r--r--src/util/wiki-data.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 8fb62db0..f0812a08 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -287,12 +287,23 @@ export function sortAlphabetically(data, {
 //  * name (or override getName)
 //  * date (or override getDate)
 export function sortChronologically(data, {
+  latestFirst = false,
   getDirectory,
   getName,
   getDate,
 } = {}) {
-  sortAlphabetically(data, {getDirectory, getName});
-  sortByDate(data, {getDate});
+  if (latestFirst) {
+    // Double reverse: Since we reverse after sorting by date, also reverse
+    // after sorting A-Z, so the second reverse restores A-Z relative
+    // positioning (for entries with the same date).
+    sortAlphabetically(data, {getDirectory, getName});
+    data.reverse();
+    sortByDate(data, {getDate});
+    data.reverse();
+  } else {
+    sortAlphabetically(data, {getDirectory, getName});
+    sortByDate(data, {getDate});
+  }
   return data;
 }