File size: 842 Bytes
19918ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { a, aside, img, p, strong } from 'https://unpkg.com/ez-html-elements'

/** Create a card object from the JSON returned from the server. */
export default (card) => {
  // Card PRIVATE:
  const caption =
    a({ href: card.url }, strong(card.title)) +
    (card.description ? p(card.description) : '')

  // Card PUBLIC:
  return Object.freeze({
    /** Generate HTML text */
    html: () => {
      switch (card.type) {
        case 'link':
        case 'video':
          return aside(
            a(
              { href: card.url, alt: card.title },
              img({
                width: card.width,
                height: card.height,
                src: card.image,
                alt: card.title
              }),
              caption
            )
          )
        default:
          return ''
      }
    }
  })
}