« get me outta code hell

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

export default {
  contentDependencies: [
    'generateColorStyleAttribute',
    'linkArtist',
    'transformContent',
  ],

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

  relations: (relation, entry) => ({
    artistLinks:
      (!empty(entry.artists) && !entry.artistDisplayText
        ? entry.artists
            .map(artist => relation('linkArtist', artist))
        : null),

    artistsContent:
      (entry.artistDisplayText
        ? relation('transformContent', entry.artistDisplayText)
        : null),

    annotationContent:
      (entry.annotation
        ? relation('transformContent', entry.annotation)
        : null),

    bodyContent:
      (entry.body
        ? relation('transformContent', entry.body)
        : null),

    colorStyle:
      relation('generateColorStyleAttribute'),
  }),

  data: (entry) => ({
    date: entry.date,
  }),

  slots: {
    color: {validate: v => v.isColor},
  },

  generate(data, relations, slots, {html, language}) {
    const artistsSpan =
      html.tag('span', {class: 'commentary-entry-artists'},
        (relations.artistsContent
          ? relations.artistsContent.slot('mode', 'inline')
       : relations.artistLinks
          ? language.formatConjunctionList(relations.artistLinks)
          : language.$('misc.artistCommentary.entry.title.noArtists')));

    const accentParts = ['misc.artistCommentary.entry.title.accent'];
    const accentOptions = {};

    if (relations.annotationContent) {
      accentParts.push('withAnnotation');
      accentOptions.annotation =
        relations.annotationContent.slot('mode', 'inline');
    }

    if (data.date) {
      accentParts.push('withDate');
      accentOptions.date =
        language.formatDate(data.date);
    }

    const accent =
      (accentParts.length > 1
        ? html.tag('span', {class: 'commentary-entry-accent'},
            language.$(...accentParts, accentOptions))
        : null);

    const titleParts = ['misc.artistCommentary.entry.title'];
    const titleOptions = {artists: artistsSpan};

    if (accent) {
      titleParts.push('withAccent');
      titleOptions.accent = accent;
    }

    const style =
      slots.color &&
        relations.colorStyle.slot('color', slots.color);

    return html.tags([
      html.tag('p', {class: 'commentary-entry-heading'},
        style,
        language.$(...titleParts, titleOptions)),

      html.tag('blockquote', {class: 'commentary-entry-body'},
        style,
        relations.bodyContent.slot('mode', 'multiline')),
    ]);
  },
};