« get me outta code hell

generateTrackCoverArtwork.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/generateTrackCoverArtwork.js
blob: 9153e2fc0a5746451555251669821f5f8c6c235c (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
export default {
  contentDependencies: [
    'generateCoverArtwork',
    'generateCoverArtworkArtTagDetails',
    'generateCoverArtworkArtistDetails',
    'generateCoverArtworkReferenceDetails',
    'image',
    'linkAlbum',
    'linkTrackReferencedArtworks',
    'linkTrackReferencingArtworks',
  ],

  extraDependencies: ['html', 'language'],

  query: (track) => ({
    artTags:
      (track.hasUniqueCoverArt
        ? track.artTags
        : track.album.artTags),

    coverArtistContribs:
      (track.hasUniqueCoverArt
        ? track.coverArtistContribs
        : track.album.coverArtistContribs),
  }),

  relations: (relation, query, track) => ({
    coverArtwork:
      relation('generateCoverArtwork'),

    image:
      relation('image'),

    artTagDetails:
      relation('generateCoverArtworkArtTagDetails',
        query.artTags),

    artistDetails:
      relation('generateCoverArtworkArtistDetails',
        query.coverArtistContribs),

    referenceDetails:
      relation('generateCoverArtworkReferenceDetails',
        track.referencedArtworks,
        track.referencedByArtworks),

    referencedArtworksLink:
      relation('linkTrackReferencedArtworks', track),

    referencingArtworksLink:
      relation('linkTrackReferencingArtworks', track),

    albumLink:
      relation('linkAlbum', track.album),
  }),

  data: (query, track) => ({
    path:
      (track.hasUniqueCoverArt
        ? ['media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension]
        : ['media.albumCover', track.album.directory, track.album.coverArtFileExtension]),

    color:
      track.color,

    dimensions:
      (track.hasUniqueCoverArt
        ? track.coverArtDimensions
        : track.album.coverArtDimensions),

    nonUnique:
      !track.hasUniqueCoverArt,

    warnings:
      query.artTags
        .filter(tag => tag.isContentWarning)
        .map(tag => tag.name),
  }),

  slots: {
    mode: {type: 'string'},

    details: {
      validate: v => v.is('tags', 'artists'),
      default: 'tags',
    },

    showReferenceLinks: {
      type: 'boolean',
      default: false,
    },

    showNonUniqueLine: {
      type: 'boolean',
      default: false,
    },
  },

  generate: (data, relations, slots, {html, language}) =>
    relations.coverArtwork.slots({
      mode: slots.mode,

      image:
        relations.image.slots({
          path: data.path,
          color: data.color,
          alt: language.$('misc.alt.trackCover'),
        }),

      dimensions: data.dimensions,
      warnings: data.warnings,

      details: [
        slots.details === 'tags' &&
          relations.artTagDetails,

        slots.details === 'artists'&&
          relations.artistDetails,

        slots.showReferenceLinks &&
          relations.referenceDetails.slots({
            referencedLink:
              relations.referencedArtworksLink,

            referencingLink:
              relations.referencingArtworksLink,
          }),

        slots.showNonUniqueLine &&
        data.nonUnique &&
          html.tag('p', {class: 'image-details'},
            {class: 'non-unique-details'},

            language.$('misc.trackArtFromAlbum', {
              album:
                relations.albumLink.slots({
                  color: false,
                }),
            })),
      ],
    }),
};