« get me outta code hell

generateArtistInfoPageTracksChunk.js « dependencies « content « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateArtistInfoPageTracksChunk.js
blob: b27a29880d2542e3b4ea191710ecaac6ab07ece9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import {stitchArrays} from '#sugar';
import {getTotalDuration} from '#wiki-data';

export default {
  contentDependencies: [
    'generateArtistInfoPageChunk',
    'generateArtistInfoPageTracksChunkItem',
    'linkAlbum',
  ],

  relations: (relation, artist, album, tracks, contribs) => ({
    template:
      relation('generateArtistInfoPageChunk'),

    albumLink:
      relation('linkAlbum', album),

    items:
      stitchArrays({
        track: tracks,
        contribs: contribs,
      }).map(({track, contribs}) =>
          relation('generateArtistInfoPageTracksChunkItem',
            artist,
            track,
            contribs)),
  }),

  data: (_artist, album, tracks, _contribs) => ({
    // STUB: This is flat-out incorrect date behavior.
    date:
      album.date,

    duration:
      getTotalDuration(tracks, {originalReleasesOnly: true}),

    durationApproximate:
      tracks
        .filter(track => track.duration && track.isOriginalRelease)
        .length > 1,
  }),

  generate: (data, relations) =>
    relations.template.slots({
      mode: 'album',
      albumLink: relations.albumLink,
      date: data.date,
      duration: data.duration,
      durationApproximate: data.durationApproximate,
      items: relations.items,
    }),
};