« get me outta code hell

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:
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;
 }