« get me outta code hell

generateTrackSocialEmbedDescription.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/generateTrackSocialEmbedDescription.js
blob: 4706aa26013e56f4f9946fe7751615b30fbd17af (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
import {empty} from '#sugar';

export default {
  extraDependencies: ['html', 'language'],

  data: (track) => ({
    artistNames:
      track.artistContribs
        .map(contrib => contrib.artist.name),

    coverArtistNames:
      track.coverArtistContribs
        .map(contrib => contrib.artist.name),
  }),

  generate: (data, {html, language}) =>
    language.encapsulate('trackPage.socialEmbed.body', baseCapsule =>
      language.encapsulate(baseCapsule, workingCapsule => {
        const workingOptions = {};

        if (!empty(data.artistNames)) {
          workingCapsule += '.withArtists';
          workingOptions.artists =
            language.formatConjunctionList(data.artistNames);
        }

        if (!empty(data.coverArtistNames)) {
          workingCapsule += '.withCoverArtists';
          workingOptions.coverArtists =
            language.formatConjunctionList(data.coverArtistNames);
        }

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