git ssb

0+

Zach! / dat-zine-library



Tree: 17911892e80acec389107af6ee6a884916b4ae85

Files: 17911892e80acec389107af6ee6a884916b4ae85 / building / components / shelving.js

1526 bytesRaw
1const html = require('choo/html')
2const _ = require('lodash')
3
4module.exports = view
5
6function view (state, emit) {
7 return html`
8 <ul id='zine-shelves'>
9 ${state.library.map(listZines)}
10 </ul>
11 `
12
13 function listZines (zine) {
14 var collection = state.params.collection
15// This could likely be muuuch prettier, need to refactor!
16 var isPartOfCollection = () => {
17 if (zine.collections) {
18 var name = decodeURI(collection)
19 return zine.collections.find(collection => _.toLower(collection) === name)
20 } else return false
21 }
22 if (collection && !isPartOfCollection()) {
23 return //nothing
24 } else {
25 var trimmedUrl = _.trimEnd(zine.url, '/')
26 var zineID = zine.title.replace(/ /g, '-')
27 var imagePath = state.covers[trimmedUrl]
28 return html`
29 <li id=${zineID}>
30 <a href=${zine.url} title=${zine.title} target="_blank">
31 <div class='zine-card'>
32 <div class='title'>
33 <h1>${zine.title}</h1>
34 </div>
35 <div class='details'>
36 <img src=${imagePath}/>
37 <p>${zine.notes}</p>
38 ${renderInfo(zine, state)}
39 </div>
40 </div>
41 </a>
42 </li>
43 `
44 }
45 }
46
47 function renderInfo (zine, state) {
48 var trimmedUrl = _.trimEnd(zine.url, '/')
49 var info = _.entries(state.info[trimmedUrl])
50 if (info) {
51 return html`
52 <div id='zine-info'>
53 <h1>Info From Zine</h1>
54 ${info.map(pair => {
55 return html`<p><strong>${pair[0]}:</strong> ${pair[1]}</p>`
56 })
57 }
58 </div>
59 `
60
61 }
62 }
63}
64

Built with git-ssb-web