« 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: e9f770f0818322b453f7f7af83cab6dd8e0e13e4 (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
import {stitchArrays} from '../../util/sugar.js';

export default {
  extraDependencies: ['html'],

  slots: {
    images: {validate: v => v.arrayOf(v.isHTML)},
    links: {validate: v => v.arrayOf(v.isHTML)},
    names: {validate: v => v.arrayOf(v.isString)},
    info: {validate: v => v.arrayOf(v.isString)},

    lazy: {validate: v => v.oneOf(v.isWholeNumber, v.isBoolean)},
  },

  generate(slots, {html}) {
    return (
      html.tag('div', {class: 'grid-listing'},
        stitchArrays({
          image: slots.images,
          link: slots.links,
          name: slots.names,
          info: slots.info,
        }).map(({image, link, name, info}, index) =>
            link.slots({
              attributes: {class: ['grid-item', 'box']},
              content: [
                image.slots({
                  thumb: 'medium',
                  square: true,
                  lazy:
                    (typeof slots.lazy === 'number'
                      ? index >= slots.lazy
                   : typeof slots.lazy === 'boolean'
                      ? slots.lazy
                      : false),
                }),
                html.tag('span', {[html.onlyIfContent]: true}, name),
                html.tag('span', {[html.onlyIfContent]: true}, info),
              ],
            }))));
  },
};