« get me outta code hell

generateContentEntry.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/generateContentEntry.js
blob: c77f744a74313e90866c3f669bd04ab2aa6b1e8f (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
114
115
116
117
118
119
120
121
122
123
import {empty} from '#sugar';

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

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

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

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

    colorStyle:
      relation('generateColorStyleAttribute'),

    date:
      relation('generateContentEntryDate', entry),
  }),

  data: (entry) => ({
    isWikiEditorEntry:
      entry.isWikiEditorCommentary ||
      entry.isWikiEditorSource,
  }),

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

  generate: (data, relations, slots, {html, language}) =>
    language.encapsulate('misc.artistCommentary.entry', entryCapsule =>
      html.tags([
        html.tag('p', {class: 'content-entry-heading'},
          slots.color &&
            relations.colorStyle.clone()
              .slot('color', slots.color),

          !html.isBlank(relations.date) &&
            {class: 'dated'},

          html.tag('span', {class: 'content-entry-heading-inner-box'},
            language.encapsulate(entryCapsule, 'title', titleCapsule => [
              html.tags([
                html.tag('span', {class: 'float-spacer'},
                  {[html.onlyIfSiblings]: true}),

                relations.date,
              ]),

              html.tag('span', {class: 'content-entry-heading-text'},
                language.encapsulate(titleCapsule, workingCapsule => {
                  const workingOptions = {};

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

                      (relations.artistsContent
                        ? relations.artistsContent.slot('mode', 'inline')
                     : relations.artistLinks
                        ? language.formatConjunctionList(relations.artistLinks)
                        : html.blank()));

                  if (!html.isBlank(artists)) {
                    workingCapsule += '.withArtists';
                    workingOptions.artists = artists;
                  }

                  let annotation = html.blank();
                  if (relations.annotationContent) {
                    relations.annotationContent.slots({
                      mode: 'inline',
                      absorbPunctuationFollowingExternalLinks: false,
                    });

                    annotation =
                      html.tag('span', {class: 'content-entry-annotation'},
                        html.metatag('chunkwrap', {split: ','},
                          relations.annotationContent));
                  }

                  if (!html.isBlank(annotation)) {
                    if (html.isBlank(artists)) {
                      workingCapsule += '.withAnnotation';
                      workingOptions.annotation = annotation;
                    } else {
                      workingCapsule += '.withAccent';
                      workingOptions.accent =
                        html.tag('span', {class: 'content-entry-accent'},
                          language.$(titleCapsule, 'accent.withAnnotation', {annotation}));

                      if (data.isWikiEditorEntry) {
                        workingCapsule += '.wikiEditor';
                      }
                    }
                  }

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

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

          data.isWikiEditorEntry &&
            {class: 'wiki-commentary'},

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