« get me outta code hell

generateContributionList.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/generateContributionList.js
blob: 4796cc025e0e4f396990d7c36d565571c979dd55 (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
export default {
  relations: (relation, contributions, formatText) => ({
    contributionLinks:
      contributions
        .map(contrib => relation('linkContribution', contrib)),

    formatText:
      relation('transformContent', formatText),
  }),

  slots: {
    attributes: {type: 'attributes', mutable: false},
    title: {type: 'html', mutable: false},

    chronologyKind: {type: 'string'},
  },

  generate(relations, slots, {html, language}) {
    const {contributionLinks} = relations;

    for (const link of contributionLinks) {
      link.setSlots({
        showAnnotation: true,
        showExternalLinks: true,
        showChronology: true,
        preventWrapping: false,
        chronologyKind: slots.chronologyKind,
      });
    }

    if (!html.isBlank(relations.formatText)) {
      return (
        html.tag('div',
          slots.attributes,
          relations.formatText.slot('mode', 'contributors'))
      );
    }

    return html.tags([
      html.tag('p',
        slots.attributes,
        slots.title),

      html.tag('ul',
        {[html.onlyIfContent]: true},

        relations.contributionLinks.length > 1 &&
        language.$order('misc.artistLink.withContribution', 0) === 'ARTIST' &&
          {class: 'offset-tooltips'},

        contributionLinks
          .map(link => html.tag('li', link)))
    ]);
  }
};