« get me outta code hell

generateMusicVideoDateLine.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/generateMusicVideoDateLine.js
blob: 40a1543861b280bc6084d02e4b9458e8ad090eee (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
function sameDay(musicVideo, thing) {
  if (!musicVideo.dateIsSpecified) return null;

  const compare = (a, b) =>
    a.toDateString() === b.toDateString();

  const album = thing.isTrack ? thing.album : thing;
  const track = thing.isTrack ? thing : null;

  if (compare(musicVideo.date, album.date)) {
    if (album.style === 'single') {
      return 'single';
    } else {
      return 'album';
    }
  }

  if (compare(musicVideo.date, track.date)) {
    return 'track';
  }

  return null;
}

export default {
  data: (musicVideo, thing) => ({
    date:
      musicVideo.date,

    dateIsSpecified:
      musicVideo.dateIsSpecified,

    sameDay:
      sameDay(musicVideo, thing),
  }),

  generate: (data, {language}) =>
    language.encapsulate('misc.musicVideo.date', capsule => [
      data.sameDay === 'album' &&
        language.$(capsule, 'sameDayAsAlbum'),

      data.sameDay === 'single' &&
        language.$(capsule, 'sameDayAsTrack'),

      data.sameDay === 'track' &&
        language.$(capsule, 'sameDayAsTrack'),

      data.sameDay === null &&
      data.dateIsSpecified &&
        language.$(capsule, {
          date:
            language.formatDate(data.date),
        }),
    ]),
};