« get me outta code hell

generateTrackSocialEmbed.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/generateTrackSocialEmbed.js
blob: d8e21e385c6b43e5c2759219983f27a35c6a804c (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
export default {
  contentDependencies: [
    'generateSocialEmbed',
    'generateTrackSocialEmbedDescription',
  ],

  extraDependencies: ['absoluteTo', 'language', 'urls'],

  relations(relation, track) {
    return {
      socialEmbed:
        relation('generateSocialEmbed'),

      description:
        relation('generateTrackSocialEmbedDescription', track),
    };
  },

  data(track) {
    const {album} = track;
    const data = {};

    data.trackName = track.name;
    data.albumName = album.name;

    data.trackDirectory = track.directory;
    data.albumDirectory = album.directory;

    if (track.hasUniqueCoverArt) {
      data.imageSource = 'track';
      data.coverArtFileExtension = track.coverArtFileExtension;
    } else if (album.hasCoverArt) {
      data.imageSource = 'album';
      data.coverArtFileExtension = album.coverArtFileExtension;
    } else {
      data.imageSource = 'none';
    }

    return data;
  },

  generate: (data, relations, {absoluteTo, language, urls}) =>
    language.encapsulate('trackPage.socialEmbed', embedCapsule =>
      relations.socialEmbed.slots({
        title:
          language.$(embedCapsule, 'title', {
            track: data.trackName,
          }),

        description:
          relations.description,

        headingContent:
          language.$(embedCapsule, 'heading', {
            album: data.albumName,
          }),

        headingLink:
          absoluteTo('localized.album', data.albumDirectory),

        imagePath:
          (data.imageSource === 'album'
            ? '/' +
              urls
                .from('shared.root')
                .to('media.albumCover', data.albumDirectory, data.coverArtFileExtension)
         : data.imageSource === 'track'
            ? '/' +
              urls
                .from('shared.root')
                .to('media.trackCover', data.albumDirectory, data.trackDirectory, data.coverArtFileExtension)
            : null),
      })),
};