« get me outta code hell

generateAdditionalNamesBox.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/generateAdditionalNamesBox.js
blob: f7fa3b00091d82b5021a350104757e8ae835c97b (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
import {stitchArrays} from '#sugar';

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

  relations: (relation, additionalNames) => ({
    names:
      additionalNames.map(({name}) =>
        relation('transformContent', name)),

    annotations:
      additionalNames.map(({annotation}) =>
        (annotation
          ? relation('transformContent', annotation)
          : null)),
  }),

  generate: (relations, {html, language}) => {
    const names =
      relations.names.map(name =>
        html.tag('span', {class: 'additional-name'},
          name.slot('mode', 'inline')));

    const annotations =
      relations.annotations.map(annotation =>
        (annotation
          ? html.tag('span', {class: 'annotation'},
              language.$('misc.additionalNames.item.annotation', {
                annotation:
                  annotation.slot('mode', 'inline'),
              }))
          : null));

    return html.tag('div', {id: 'additional-names-box'}, [
      html.tag('p',
        language.$('misc.additionalNames.title')),

      html.tag('ul',
        stitchArrays({name: names, annotation: annotations})
          .map(({name, annotation}) =>
            html.tag('li',
              (annotation
                ? language.$('misc.additionalNames.item.withAnnotation', {name, annotation})
                : language.$('misc.additionalNames.item', {name}))))),
    ]);
  },
};