« get me outta code hell

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

export default {
  contentDependencies: ['generateTextWithTooltip'],
  extraDependencies: ['html', 'language'],

  relations: (relation) => ({
    textWithTooltip:
      relation('generateTextWithTooltip'),
  }),

  slots: {
    content: {
      type: 'html',
      mutable: false,
    },

    annotation: {
      type: 'html',
      mutable: false,
    },

    otherArtistLinks: {
      validate: v => v.strictArrayOf(v.isHTML),
    },

    rereleaseTooltip: {
      type: 'html',
      mutable: false,
    },

    firstReleaseTooltip: {
      type: 'html',
      mutable: false,
    },

    extraDetails: {
      type: 'html',
      mutable: false,
    },
  },

  generate: (relations, slots, {html, language}) =>
    language.encapsulate('artistPage.creditList.entry', entryCapsule =>
      html.tag('li',
        slots.rerelease && {class: 'rerelease'},

        html.tags([
          language.encapsulate(entryCapsule, workingCapsule => {
            const workingOptions = {entry: slots.content};

            if (!html.isBlank(slots.rereleaseTooltip)) {
              workingCapsule += '.rerelease';
              workingOptions.rerelease =
                relations.textWithTooltip.slots({
                  attributes: {class: 'rerelease'},
                  text: language.$(entryCapsule, 'rerelease.term'),
                  tooltip: slots.rereleaseTooltip,
                });

              return language.$(workingCapsule, workingOptions);
            }

            if (!html.isBlank(slots.firstReleaseTooltip)) {
              workingCapsule += '.firstRelease';
              workingOptions.firstRelease =
                relations.textWithTooltip.slots({
                  attributes: {class: 'first-release'},
                  text: language.$(entryCapsule, 'firstRelease.term'),
                  tooltip: slots.firstReleaseTooltip,
                });

              return language.$(workingCapsule, workingOptions);
            }

            let anyAccent = false;

            if (!empty(slots.otherArtistLinks)) {
              anyAccent = true;
              workingCapsule += '.withArtists';
              workingOptions.artists =
                language.formatConjunctionList(slots.otherArtistLinks);
            }

            if (!html.isBlank(slots.annotation)) {
              anyAccent = true;
              workingCapsule += '.withAnnotation';
              workingOptions.annotation = slots.annotation;
            }

            if (anyAccent) {
              return language.$(workingCapsule, workingOptions);
            } else {
              return slots.content;
            }
          }),

          html.tag('span', {class: 'extra-details'},
            {[html.onlyIfContent]: true},

            slots.extraDetails),
        ]))),
};