« get me outta code hell

generateQuickDescription.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/generateQuickDescription.js
blob: 3dadfbcf5c9cbeb8f230a4198466fce16ec5832d (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
export default {
  contentDependencies: ['transformContent'],
  extraDependencies: ['html', 'language'],

  relations: (relation, thing) =>
    ({description:
        (thing.descriptionShort || thing.description
          ? relation('transformContent',
              thing.descriptionShort ?? thing.description)
          : null)}),

  data: (thing) =>
    ({hasLongerDescription:
        thing.description &&
        thing.descriptionShort &&
        thing.descriptionShort !== thing.description}),

  slots: {
    infoPageLink: {
      type: 'html',
      mutable: true,
    },
  },

  generate: (data, relations, slots, {html, language}) =>
    html.tag('p', {class: 'quick-info'},
      {[html.joinChildren]: html.tag('br')},
      {[html.onlyIfContent]: true},

      [
        relations.description?.slot('mode', 'inline'),

        data.hasLongerDescription &&
        slots.infoPageLink &&
          language.$('misc.quickDescription.moreInfo', {
            link:
              slots.infoPageLink
                .slot('content', language.$('misc.quickDescription.moreInfo.link')),
          }),
      ]),
};