From 7eda6868381e9e145d503294837f6f60de7e38e0 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 18 Apr 2023 21:09:10 -0300 Subject: content: misc. changes, groups divided by tracks, relation sections --- src/content/util/groupTracksByGroup.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/content/util/groupTracksByGroup.js (limited to 'src/content/util') diff --git a/src/content/util/groupTracksByGroup.js b/src/content/util/groupTracksByGroup.js new file mode 100644 index 00000000..bae2c8c5 --- /dev/null +++ b/src/content/util/groupTracksByGroup.js @@ -0,0 +1,23 @@ +import {empty} from '../../util/sugar.js'; + +export default 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 { + other.get('other').push(track); + } + } + + for (const [key, tracks] of lists.entries()) { + if (empty(tracks)) { + lists.delete(key); + } + } + + return lists; +} -- cgit 1.3.0-6-gf8a5