« get me outta code hell

generateAlbumSocialEmbedDescription.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/generateAlbumSocialEmbedDescription.js
blob: 69c39c3a7e58d4ed78b127e8af524e7d4333657d (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
import {accumulateSum} from '#sugar';

export default {
  extraDependencies: ['language'],

  data: (album) => ({
    duration:
      accumulateSum(album.tracks, track => track.duration),

    tracks:
      album.tracks.length,

    date:
      album.date,
  }),

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

      if (data.duration > 0) {
        workingCapsule += '.withDuration';
        workingOptions.duration =
          language.formatDuration(data.duration);
      }

      if (data.tracks > 0) {
        workingCapsule += '.withTracks';
        workingOptions.tracks =
          language.countTracks(data.tracks, {unit: true});
      }

      if (data.date) {
        workingCapsule += '.withReleaseDate';
        workingOptions.date =
          language.formatDate(data.date);
      }

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