« get me outta code hell

generateCoverGrid.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/generateCoverGrid.js
blob: fdd9f8b73fddc5b8c9d927276481f7145760e959 (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
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' */],
                },
              });
            })));
      },
    });
  },
};