« get me outta code hell

generateGroupInfoPageAlbumsListItem.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/generateGroupInfoPageAlbumsListItem.js
blob: f0e1e39cb469f6f08073d57d0c52780e9475eb31 (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
import {empty} from '#sugar';

export default {
  contentDependencies: [
    'generateAbsoluteDatetimestamp',
    'generateArtistCredit',
    'generateColorStyleAttribute',
    'linkAlbum',
    'linkGroup',
  ],

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

  query: (album, group) => {
    const otherCategory =
      album.groups
        .map(group => group.category)
        .find(category => category !== group.category);

    const otherGroups =
      album.groups
        .filter(group => group.category === otherCategory);

    return {otherGroups};
  },

  relations: (relation, query, album) => ({
    colorStyle:
      relation('generateColorStyleAttribute', album.color),

    albumLink:
      relation('linkAlbum', album),

    datetimestamp:
      (album.date
        ? relation('generateAbsoluteDatetimestamp', album.date)
        : null),

    artistCredit:
      relation('generateArtistCredit', album.artistContribs, []),

    otherGroupLinks:
      query.otherGroups
        .map(group => relation('linkGroup', group)),
  }),

  slots: {
    accentMode: {
      validate: v => v.is('groups', 'artists'),
    },
  },

  generate: (relations, slots, {html, language}) =>
    html.tag('li',
      relations.colorStyle,

      language.encapsulate('groupInfoPage.albumList.item', itemCapsule =>
        language.encapsulate(itemCapsule, workingCapsule => {
          const workingOptions = {};

          workingOptions.album =
            relations.albumLink.slot('color', false);

          const yearCapsule = language.encapsulate(itemCapsule, 'withYear');

          if (relations.datetimestamp) {
            workingCapsule += '.withYear';
            workingOptions.yearAccent =
              language.$(yearCapsule, 'accent', {
                year:
                  relations.datetimestamp.slots({style: 'year', tooltip: true}),
              });
          }

          const otherGroupCapsule = language.encapsulate(itemCapsule, 'withOtherGroup');

          if (slots.accentMode === 'groups' && !empty(relations.otherGroupLinks)) {
            workingCapsule += '.withOtherGroup';
            workingOptions.otherGroupAccent =
              html.tag('span', {class: 'other-group-accent'},
                language.$(otherGroupCapsule, 'accent', {
                  groups:
                    language.formatConjunctionList(
                      relations.otherGroupLinks.map(groupLink =>
                        groupLink.slot('color', false))),
                }));
          }

          const artistCapsule = language.encapsulate(itemCapsule, 'withArtists');
          const {artistCredit} = relations;

          artistCredit.setSlots({
            normalStringKey:
              artistCapsule + '.by',

            featuringStringKey:
              artistCapsule + '.featuring',

            normalFeaturingStringKey:
              artistCapsule + '.by.featuring',
          });

          if (slots.accentMode === 'artists' && !html.isBlank(artistCredit)) {
            workingCapsule += '.withArtists';
            workingOptions.by =
              html.tag('span', {class: 'by'},
                html.metatag('chunkwrap', {split: ','},
                  html.resolve(artistCredit)));
          }

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