« 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: f7f455c1fb5c3ffc7e37323ebbde619d9fc1d0bc (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
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:
          language.formatConjunctionList(
            stitchArrays({
              trackLink: relations.trackLinks,
              albumLink: relations.albumLinks,
            }).map(({trackLink, albumLink}) =>
                (albumLink
                  ? language.$(capsule, 'trackOnAlbum', {
                      track: trackLink,
                      album: albumLink,
                    })
                  : trackLink))),
      })),
};