« 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: 136769ac2fa884ec01ca5253a7c690681e27b239 (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'},
  },

  generate(data, relations, slots, {html, language}) {
    return html.tag('p',
      {
        [html.joinChildren]: html.tag('br'),
        [html.onlyIfContent]: true,
        class:' quick-info',
      },
      [
        relations.description?.slot('mode', 'inline'),

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