« get me outta code hell

generateTrackInfoPagePreviousProductionLine.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/generateTrackInfoPagePreviousProductionLine.js
blob: b2f50cf39484ec1919115e7b6eb525305e8db5f1 (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
import {stitchArrays} from '#sugar';
import {getKebabCase} from '#wiki-data';

export default {
  relations: (relation, track) => ({
    trackLinks:
      track.followingProductionTracks
        .map(track => relation('linkTrack', track)),

    albumLinks:
      track.followingProductionTracks
        .map(following =>
          (following.album !== track.album &&
           getKebabCase(following.name) === getKebabCase(track.name)

            ? relation('linkAlbum', following.album)
            : null)),
  }),

  generate: (relations, {language}) =>
    language.encapsulate('releaseInfo.previousProduction', capsule =>
      language.$(capsule, {
        [language.onlyIfOptions]: ['tracks'],

        tracks:
          stitchArrays({
            trackLink: relations.trackLinks,
            albumLink: relations.albumLinks,
          }).map(({trackLink, albumLink}) =>
              (albumLink
                ? language.$(capsule, 'trackOnAlbum', {
                    track: trackLink,
                    album: albumLink,
                  })
                : trackLink)),
      })),
};