« 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: 7712d9f6a1eac0d0c829f9abce0fe387fe2ccb25 (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
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) => ({
    isWikiEditorCommentary:
      entry.isWikiEditorCommentary,
  }),

  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'},

          language.encapsulate(entryCapsule, 'title', titleCapsule => [
            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;
                }

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

                    (relations.annotationContent
                      ? relations.annotationContent.slots({
                          mode: 'inline',
                          absorbPunctuationFollowingExternalLinks: false,
                        })
                      : html.blank()));

                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.isWikiEditorCommentary) {
                      workingCapsule += '.wikiEditor';
                    }
                  }
                }

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

            relations.date,
          ])),

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

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

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