« get me outta code hell

generateWikiHomepageAlbumCarouselRow.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/generateWikiHomepageAlbumCarouselRow.js
blob: 3068d9518b092946e6e677c832b694ca8341bf5a (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
import {stitchArrays} from '#sugar';

export default {
  contentDependencies: ['generateCoverCarousel', 'image', 'linkAlbum'],

  relations: (relation, row) => ({
    coverCarousel:
      relation('generateCoverCarousel'),

    links:
      row.albums
        .map(album => relation('linkAlbum', album)),

    images:
      row.albums
        .map(album => relation('image', album.artTags)),
  }),

  data: (row) => ({
    paths:
      row.albums.map(album =>
        (album.hasCoverArt
          ? ['media.albumCover', album.directory, album.coverArtFileExtension]
          : null)),
  }),

  generate: (data, relations) =>
    relations.coverCarousel.slots({
      links:
        relations.links,

      images:
        stitchArrays({
          image: relations.images,
          path: data.paths,
        }).map(({image, path}) =>
            image.slot('path', path)),
    }),
};