« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js')
-rw-r--r--src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js b/src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js
new file mode 100644
index 00000000..3068d951
--- /dev/null
+++ b/src/content/dependencies/generateWikiHomepageAlbumCarouselRow.js
@@ -0,0 +1,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)),
+    }),
+};