« get me outta code hell

generateArtistInfoPageCommentaryChunkedList.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/generateArtistInfoPageCommentaryChunkedList.js
blob: 49399c99535387be5e274a13bda353228d102810 (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
import {stitchArrays} from '#sugar';

import {
  chunkByProperties,
  sortAlbumsTracksChronologically,
  sortEntryThingPairs,
} from '#wiki-data';

export default {
  contentDependencies: [
    'generateArtistInfoPageChunk',
    'generateArtistInfoPageChunkItem',
    'generateArtistInfoPageOtherArtistLinks',
    'linkAlbum',
    'linkTrack',
  ],

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

  query(artist) {
    // TODO: Add and integrate wallpaper and banner date fields (#90)
    // This will probably only happen once all artworks follow a standard
    // shape (#70) and get their own sorting function. Read for more info:
    // https://github.com/hsmusic/hsmusic-wiki/issues/90#issuecomment-1607422961

    const entries = [
      ...artist.albumsAsCommentator.map(album => ({
        thing: album,
        entry: {
          type: 'album',
          album,
        },
      })),

      ...artist.tracksAsCommentator.map(track => ({
        thing: track,
        entry: {
          type: 'track',
          album: track.album,
          track,
        },
      })),
    ];

    sortEntryThingPairs(entries, sortAlbumsTracksChronologically);

    const chunks =
      chunkByProperties(
        entries.map(({entry}) => entry),
        ['album']);

    return {chunks};
  },

  relations(relation, query) {
    return {
      chunks:
        query.chunks.map(() => relation('generateArtistInfoPageChunk')),

      albumLinks:
        query.chunks.map(({album}) => relation('linkAlbum', album)),

      items:
        query.chunks.map(({chunk}) =>
          chunk.map(() => relation('generateArtistInfoPageChunkItem'))),

      itemTrackLinks:
        query.chunks.map(({chunk}) =>
          chunk.map(({track}) => track ? relation('linkTrack', track) : null)),
    };
  },

  data(query) {
    return {
      itemTypes:
        query.chunks.map(({chunk}) =>
          chunk.map(({type}) => type)),
    };
  },

  generate(data, relations, {html, language}) {
    return html.tag('dl',
      stitchArrays({
        chunk: relations.chunks,
        albumLink: relations.albumLinks,

        items: relations.items,
        itemTrackLinks: relations.itemTrackLinks,
        itemTypes: data.itemTypes,
      }).map(({chunk, albumLink, items, itemTrackLinks, itemTypes}) =>
          chunk.slots({
            mode: 'album',
            albumLink,
            items:
              stitchArrays({
                item: items,
                trackLink: itemTrackLinks,
                type: itemTypes,
              }).map(({item, trackLink, type}) =>
                item.slots({
                  content:
                    (type === 'album'
                      ? html.tag('i',
                          language.$('artistPage.creditList.entry.album.commentary'))
                      : language.$('artistPage.creditList.entry.track', {
                          track: trackLink,
                        })),
                })),
          })));
  },
};