« get me outta code hell

generateTrackArtistCommentarySection.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/generateTrackArtistCommentarySection.js
blob: e3041d3a1745e8ec961eb30cd4601447b7272226 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import {empty, stitchArrays} from '#sugar';

export default {
  contentDependencies: [
    'generateCommentaryEntry',
    'generateContentHeading',
    'linkAlbum',
    'linkTrack',
  ],

  extraDependencies: ['html', 'language'],

  query: (track) => ({
    otherSecondaryReleasesWithCommentary:
      track.otherReleases
        .filter(track => !track.isMainRelease)
        .filter(track => !empty(track.commentary)),
  }),

  relations: (relation, query, track) => ({
    contentHeading:
      relation('generateContentHeading'),

    mainReleaseTrackLink:
      (track.isSecondaryRelease
        ? relation('linkTrack', track.mainReleaseTrack)
        : null),

    mainReleaseArtistCommentaryEntries:
      (track.isSecondaryRelease
        ? track.mainReleaseTrack.commentary
            .map(entry => relation('generateCommentaryEntry', entry))
        : null),

    thisReleaseAlbumLink:
      relation('linkAlbum', track.album),

    artistCommentaryEntries:
      track.commentary
        .map(entry => relation('generateCommentaryEntry', entry)),

    otherReleaseTrackLinks:
      query.otherSecondaryReleasesWithCommentary
        .map(track => relation('linkTrack', track)),
  }),

  data: (query, track) => ({
    name:
      track.name,

    isSecondaryRelease:
      track.isSecondaryRelease,

    mainReleaseName:
      (track.isSecondaryRelease
        ? track.mainReleaseTrack.name
        : null),

    mainReleaseAlbumName:
      (track.isSecondaryRelease
        ? track.mainReleaseTrack.album.name
        : null),

    mainReleaseAlbumColor:
      (track.isSecondaryRelease
        ? track.mainReleaseTrack.album.color
        : null),

    otherReleaseAlbumNames:
      query.otherSecondaryReleasesWithCommentary
        .map(track => track.album.name),

    otherReleaseAlbumColors:
      query.otherSecondaryReleasesWithCommentary
        .map(track => track.album.color),
  }),

  generate: (data, relations, {html, language}) =>
    language.encapsulate('misc.artistCommentary', capsule =>
      html.tags([
        relations.contentHeading.clone()
          .slots({
            attributes: {id: 'artist-commentary'},
            title: language.$('misc.artistCommentary'),
          }),

        data.isSecondaryRelease &&
          html.tags([
            html.tag('p', {class: ['drop', 'commentary-drop']},
              {[html.onlyIfSiblings]: true},

              language.encapsulate(capsule, 'info.fromMainRelease', workingCapsule => {
                const workingOptions = {};

                workingOptions.album =
                  relations.mainReleaseTrackLink.slots({
                    content:
                      data.mainReleaseAlbumName,

                    color:
                      data.mainReleaseAlbumColor,
                  });

                if (data.name !== data.mainReleaseName) {
                  workingCapsule += '.namedDifferently';
                  workingOptions.name =
                    html.tag('i', data.mainReleaseName);
                }

                return language.$(workingCapsule, workingOptions);
              })),

            relations.mainReleaseArtistCommentaryEntries,
          ]),

        html.tags([
          data.isSecondaryRelease &&
          !html.isBlank(relations.mainReleaseArtistCommentaryEntries) &&
            html.tag('p', {class: ['drop', 'commentary-drop']},
              {[html.onlyIfSiblings]: true},

              language.$(capsule, 'info.releaseSpecific', {
                album:
                  relations.thisReleaseAlbumLink,
              })),

          relations.artistCommentaryEntries,
        ]),

        html.tag('p', {class: ['drop', 'commentary-drop']},
          {[html.onlyIfContent]: true},

          language.encapsulate(capsule, 'info.seeSpecificReleases', workingCapsule => {
            const workingOptions = {};

            workingOptions[language.onlyIfOptions] = ['albums'];

            workingOptions.albums =
              language.formatUnitList(
                stitchArrays({
                  trackLink: relations.otherReleaseTrackLinks,
                  albumName: data.otherReleaseAlbumNames,
                  albumColor: data.otherReleaseAlbumColors,
                }).map(({trackLink, albumName, albumColor}) =>
                    trackLink.slots({
                      content: language.sanitize(albumName),
                      color: albumColor,
                    })));

            if (!html.isBlank(relations.artistCommentaryEntries)) {
              workingCapsule += '.withMainCommentary';
            }

            return language.$(workingCapsule, workingOptions);
          })),
      ])),
};