« 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: 7c4aed8064aebf43bf0b7253ec810001a32e289b (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: [
    '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}) =>
    language.encapsulate('misc.artistCommentary.entry', entryCapsule =>
      html.tags([
        html.tag('p', {class: 'commentary-entry-heading'},
          slots.color &&
            relations.colorStyle.clone()
              .slot('color', slots.color),

          language.encapsulate(entryCapsule, 'title', titleCapsule => [
            html.tag('time',
              {[html.onlyIfContent]: true},

              language.$(titleCapsule, 'date', {
                [language.onlyIfOptions]: ['date'],

                date:
                  language.formatDate(data.date),
              })),

            language.encapsulate(titleCapsule, workingCapsule => {
              const workingOptions = {};

              workingOptions.artists =
                html.tag('span', {class: 'commentary-entry-artists'},
                  (relations.artistsContent
                    ? relations.artistsContent.slot('mode', 'inline')
                 : relations.artistLinks
                    ? language.formatConjunctionList(relations.artistLinks)
                    : language.$(titleCapsule, 'noArtists')));

              const accent =
                html.tag('span', {class: 'commentary-entry-accent'},
                  {[html.onlyIfContent]: true},

                  language.encapsulate(titleCapsule, 'accent', accentCapsule =>
                    language.encapsulate(accentCapsule, workingCapsule => {
                      const workingOptions = {};

                      if (relations.annotationContent) {
                        workingCapsule += '.withAnnotation';
                        workingOptions.annotation =
                          relations.annotationContent.slot('mode', 'inline');
                      }

                      if (workingCapsule === accentCapsule) {
                        return html.blank();
                      } else {
                        return language.$(workingCapsule, workingOptions);
                      }
                    })));

              if (!html.isBlank(accent)) {
                workingCapsule += '.withAccent';
                workingOptions.accent = accent;
              }

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

        html.tag('blockquote', {class: 'commentary-entry-body'},
          slots.color &&
            relations.colorStyle.clone()
              .slot('color', slots.color),

          relations.bodyContent.slot('mode', 'multiline')),
      ])),
};