« get me outta code hell

generateTrackInfoPageFeaturedByFlashesList.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/generateTrackInfoPageFeaturedByFlashesList.js
blob: 5958be9aaeb9ea54b58d15d9dbc4b22b67f34266 (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
import {sortFlashesChronologically} from '#sort';
import {stitchArrays} from '#sugar';

export default {
  contentDependencies: ['linkFlash', 'linkTrack'],
  extraDependencies: ['html', 'language', 'wikiData'],

  sprawl: ({wikiInfo}) => ({
    enableFlashesAndGames:
      wikiInfo.enableFlashesAndGames,
  }),

  query: (sprawl, track) => ({
    sortedFeatures:
      (sprawl.enableFlashesAndGames
        ? sortFlashesChronologically(
            [track, ...track.otherReleases].flatMap(track =>
              track.featuredInFlashes.map(flash => ({
                flash,
                track,

                // These properties are only used for the sort.
                act: flash.act,
                date: flash.date,
              }))))
        : []),
  }),

  relations: (relation, query, _sprawl, track) => ({
    flashLinks:
      query.sortedFeatures
        .map(({flash}) => relation('linkFlash', flash)),

    trackLinks:
      query.sortedFeatures
        .map(({track: directlyFeaturedTrack}) =>
          (directlyFeaturedTrack === track
            ? null
            : relation('linkTrack', directlyFeaturedTrack))),
  }),

  generate: (relations, {html, language}) =>
    html.tag('ul',
      {[html.onlyIfContent]: true},

      stitchArrays({
        flashLink: relations.flashLinks,
        trackLink: relations.trackLinks,
      }).map(({flashLink, trackLink}) => {
          const attributes = html.attributes();
          const parts = ['releaseInfo.flashesThatFeature.item'];
          const options = {flash: flashLink};

          if (trackLink) {
            attributes.add('class', 'rerelease');
            parts.push('asDifferentRelease');
            options.track = trackLink;
          }

          return html.tag('li', attributes, language.$(...parts, options));
        })),
};