« get me outta code hell

generateTrackNavLinks.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/generateTrackNavLinks.js
blob: 89da171ac612cfe1a2abb0a3b4d3518cbcc46f94 (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
export default {
  contentDependencies: ['linkAlbum', 'linkTrack'],
  extraDependencies: ['html', 'language'],

  relations: (relation, track) => ({
    albumLink:
      relation('linkAlbum', track.album),

    trackLink:
      relation('linkTrack', track),
  }),

  data: (track) => ({
    hasTrackNumbers:
      track.album.hasTrackNumbers,

    trackNumber:
      track.album.tracks.indexOf(track) + 1,
  }),

  slots: {},

  generate: (data, relations, slots, {html, language}) =>
    language.encapsulate('trackPage.nav', navCapsule => [
      {auto: 'home'},

      {html: relations.albumLink.slot('color', false)},

      {
        html:
          language.encapsulate(navCapsule, 'track', workingCapsule => {
            const workingOptions = {};

            workingOptions.track =
              relations.trackLink
                .slot('attributes', {class: 'current'});

            if (data.hasTrackNumbers) {
              workingCapsule += '.withNumber';
              workingOptions.number = data.trackNumber;
            }

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