« 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/generateTrackListDividedByGroups.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateTrackListDividedByGroups.js')
-rw-r--r--src/content/dependencies/generateTrackListDividedByGroups.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/content/dependencies/generateTrackListDividedByGroups.js b/src/content/dependencies/generateTrackListDividedByGroups.js
index a9326205..5ab53068 100644
--- a/src/content/dependencies/generateTrackListDividedByGroups.js
+++ b/src/content/dependencies/generateTrackListDividedByGroups.js
@@ -1,6 +1,26 @@
 import {empty, stitchArrays} from '#sugar';
 
-import groupTracksByGroup from '../util/groupTracksByGroup.js';
+function groupTracksByGroup(tracks, groups) {
+  const lists = new Map(groups.map(group => [group, []]));
+  lists.set('other', []);
+
+  for (const track of tracks) {
+    const group = groups.find(group => group.albums.includes(track.album));
+    if (group) {
+      lists.get(group).push(track);
+    } else {
+      lists.get('other').push(track);
+    }
+  }
+
+  for (const [key, tracks] of lists.entries()) {
+    if (empty(tracks)) {
+      lists.delete(key);
+    }
+  }
+
+  return lists;
+}
 
 export default {
   contentDependencies: [