git ssb

0+

Zach! / dat-zine-library



Commit c991b08f5186ef2bacdf5ac26c051324be0e3fd8

Add collections as option on zine

Zach committed on 7/8/2018, 11:41:09 AM
Parent: 1d00890a14bdf0c9171a35b91badb806876cffe6

Files changed

volunteers/branchManager.jschanged
zines/11-killer-app-ideas.txtchanged
zines/a-future-vision.txtchanged
volunteers/branchManager.jsView
@@ -1,21 +1,22 @@
11 const smarkt = require('smarkt')
22 const _ = require('lodash')
33 const html = require('nanohtml')
44
5-
65 var archive = new DatArchive(window.location)
76
87 function store (state, emitter) {
98 state.library = []
109 state.info = {}
1110 state.covers = {}
1211 state.identity = ''
12 + state.collections = []
1313
1414 emitter.on('DOMContentLoaded', function () {
1515 setIdentity()
1616 archive.readdir('zines')
1717 .then(zines => mapToState(zines))
18 + console.log({state})
1819 })
1920
2021 emitter.on('update library', function (zine) {
2122 addToLibrary(zine)
@@ -30,8 +31,10 @@
3031 var textJson = smarkt.parse(rawText)
3132 addToLibrary(textJson)
3233 addZineInfo(textJson.url)
3334 addZineCover(textJson.url)
35 + gatherCollections(textJson.collections)
36 + cleanCollections(state.collections)
3437 })
3538 })
3639 }
3740
@@ -39,13 +42,27 @@
3942 state.library = [...state.library, text]
4043 emitter.emit('pushState')
4144 }
4245
46 + function gatherCollections (collections) {
47 + if (collections) {
48 + state.collections = [...state.collections, collections]
49 + emitter.emit('pushState')
50 + }
51 + }
52 +
53 + function cleanCollections (collections) {
54 + collections = _.flatten(collections)
55 + collections = collections.map(collection => _.toLower(collection))
56 + state.collections = _.uniq(collections)
57 + emitter.emit('pushState')
58 + }
59 +
4360 function addZineInfo (datUrl) {
4461 var zine = new DatArchive(datUrl)
4562 zine.readFile('distro/info.txt')
4663 .then(text => {
47- mapInfoToState(text, zine['url'])
64 + mapInfoToState(text, zine['url'])
4865 })
4966 }
5067
5168 function addZineCover (datUrl) {
@@ -66,9 +83,9 @@
6683 var cover = files.find(file => sansExtension(file) === 'cover')
6784 state.covers[datUrl] = `${datUrl}/distro/${cover}`
6885 emitter.emit('pushState')
6986 }
70-
87 +
7188 async function setIdentity () {
7289 var info = await archive.getInfo()
7390 if (info.isOwner) {
7491 state.identity = 'librarian'
zines/11-killer-app-ideas.txtView
@@ -1,5 +1,10 @@
11 title: 11 killer app ideas
22 ----
33 url: dat://86220354e57b0ac6dc3ef47ac9f8f75b62aebcd079d9688f2d7ede0af6abfba3/
44 ----
5-notes: i made this one too.
5 +notes: i made this one too.
6 +----
7 +collections:
8 + - comedy
9 + - technology
10 + - From The Librarian
zines/a-future-vision.txtView
@@ -1,5 +1,12 @@
11 title: a future vision
22 ----
33 url: dat://b36fd62869568a05bc9e96c1acee778a1b94cd8647ec55e42159d12846d8c00f/
44 ----
5-notes: good notes.
5 +notes: good notes.
6 +----
7 +collections:
8 + - From The Librarian
9 + - solarpunk
10 + - speculative non-fiction
11 + - emo
12 +

Built with git-ssb-web