« 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/generateCoverGrid.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/dependencies/generateCoverGrid.js')
-rw-r--r--src/content/dependencies/generateCoverGrid.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/content/dependencies/generateCoverGrid.js b/src/content/dependencies/generateCoverGrid.js
new file mode 100644
index 0000000..fdd9f8b
--- /dev/null
+++ b/src/content/dependencies/generateCoverGrid.js
@@ -0,0 +1,44 @@
+export default {
+  extraDependencies: ['html'],
+
+  generate({html}) {
+    return html.template({
+      annotation: `generateCoverGrid`,
+
+      slots: {
+        images: {validate: v => v.arrayOf(v.isHTML)},
+        links: {validate: v => v.arrayOf(v.isHTML)},
+        names: {validate: v => v.arrayOf(v.isString)},
+
+        lazy: {validate: v => v.oneOf(v.isWholeNumber, v.isBoolean)},
+      },
+
+      content(slots) {
+        return (
+          html.tag('div', {class: 'grid-listing'},
+            slots.images.map((image, i) => {
+              const link = slots.links[i];
+              const name = slots.names[i];
+              return link.slots({
+                content: [
+                  image.slots({
+                    thumb: 'medium',
+                    lazy:
+                      (typeof slots.lazy === 'number'
+                        ? i >= slots.lazy
+                     : typeof slots.lazy === 'boolean'
+                        ? slots.lazy
+                        : false),
+                    square: true,
+                  }),
+                  html.tag('span', name),
+                ],
+                attributes: {
+                  class: ['grid-item', 'box', /* large && 'large-grid-item' */],
+                },
+              });
+            })));
+      },
+    });
+  },
+};