diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-04-18 21:09:10 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-04-18 21:09:10 -0300 |
commit | 7eda6868381e9e145d503294837f6f60de7e38e0 (patch) | |
tree | d7b5b03557549066562a95f5422a1b9251f2513f /src/content/util | |
parent | c504e1dd0497edc694bd594052728ffb39af70a8 (diff) |
content: misc. changes, groups divided by tracks, relation sections
Diffstat (limited to 'src/content/util')
-rw-r--r-- | src/content/util/groupTracksByGroup.js | 23 |
1 files changed, 23 insertions, 0 deletions
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; +} |