git ssb

0+

Zach! / dat-zine-library



Commit 623ff906a993e064e9317ffbb5d9040bb68b975e

title coming from distro/ now

Zach committed on 6/26/2018, 2:33:47 AM
Parent: bfa5d0d4750109fb027d52d8738df5830003c664

Files changed

building/aesthetic/stylesheets/colors-and-fonts.csschanged
building/aesthetic/stylesheets/main.csschanged
building/components/actionButtons.jschanged
building/components/library.jschanged
building/components/newZineForm.jschanged
building/components/branchPlacard.jsadded
building/components/newBranchForm.jsadded
index.jschanged
volunteers/addingZines.jsdeleted
volunteers/addNewZines.jsadded
volunteers/jobs.jsdeleted
volunteers/branchManager.jsadded
volunteers/displayBranchInfo.jsadded
volunteers/setBranchName.jsadded
distro/info.txtadded
building/aesthetic/stylesheets/colors-and-fonts.cssView
@@ -11,15 +11,27 @@
1111 --add-button-bg: peachpuff;
1212 --add-button-text: indigo;
1313 --add-button-hover: lavender;
1414
15 + --branch-button-bg: peachpuff;
16 + --branch-button-text: indigo;
17 + --branch-button-hover: lavender;
18 +
1519 --new-zine-form-bg: peachpuff;
1620 --new-zine-form-text: indigo;
1721 --new-zine-form-border: gray;
1822 --new-zine-form-shadow: rgba(93, 87, 87, 0.53);
1923 --new-zine-form-submit-bg: white;
2024 --new-zine-form-submit-bg-hover: lavender;
2125 --new-zine-form-submit-text: indigo;
26 +
27 + --new-branch-form-bg: peachpuff;
28 + --new-branch-form-text: indigo;
29 + --new-branch-form-border: gray;
30 + --new-branch-form-shadow: rgba(93, 87, 87, 0.53);
31 + --new-branch-form-submit-bg: white;
32 + --new-branch-form-submit-bg-hover: lavender;
33 + --new-branch-form-submit-text: indigo;
2234 }
2335
2436 /* Fonts
2537 ------*/
building/aesthetic/stylesheets/main.cssView
@@ -15,14 +15,22 @@
1515 grid-template-columns: 1fr 1fr;
1616 grid-gap: 2em;
1717 }
1818
19-#welcome-title{
19 +#branch-placard{
20 + margin: 0.5em;
21 + width: 50%;
22 + text-align: justify;
23 +}
24 +
25 +#branch-placard h1{
2026 font-family: arial;
27 + font-size: 2em;
2128 font-weight: 100;
2229 letter-spacing: 0.15em;
2330 }
24-ul{
31 +
32 +#zine-shelves ul{
2533 padding: none;
2634 margin: none;
2735 }
2836
@@ -77,39 +85,51 @@
7785 background-color: var(--add-button-hover);
7886 color: indigo;
7987 }
8088
81-#add-button:focus{
82- outline-width: 0px;
89 +.invisible{
90 + display: none;
8391 }
8492
8593 #branch-button{
86- background-color: pink;
87- color: blue;
94 + font-size: 1.3em;
95 + background-color: var(--branch-button-bg);
96 + color: var(--branch-button-text);
8897 }
8998
90-#new-zine-form{
99 +.form-card{
91100 position: fixed;
92101 z-index: 1;
93102 right: -60%;
94- background: var(--new-zine-form-bg);
95- color: indigo;
96103 width: 40%;
97104 display: flex;
98105 flex-direction: column;
99106 justify-content: space-between;
100107 align-items: left;
101108 border: 1px outset gray;
102- box-shadow: -2px 4px 20px 6px var(--new-zine-form-shadow);
109 + box-shadow: -2px 4px 20px 6px var(--new-branch-form-shadow);
103110 }
104111
105-#new-zine-form h1{
112 +#new-branch-form.form-card{
113 + background: var(--new-branch-form-bg);
114 + color: var(--new-branch-form-text);;
115 +}
116 +#new-zine-form.form-card{
117 + background: var(--new-zine-form-bg);
118 + color: var(--new-zine-form-text);;
119 +}
120 +
121 +.form-card h1{
106122 margin-top: 0;
107123 font-family: arial;
108124 padding: 0.3em;
109125 }
110126
111-#new-zine-form form{
127 +.form-card p{
128 + padding-left: 1em;
129 + }
130 +
131 +.form-card form{
112132 height: 100%;
113133 width: 100%;
114134 display: flex;
115135 flex-direction: column;
@@ -117,28 +137,28 @@
117137 font-size: 24px;
118138
119139 }
120140
121-#new-zine-form label{
141 +.form-card label{
122142 padding-left: 1em;
123143 margin-bottom: 1em;
124144 }
125145
126-#new-zine-form input{
146 +.form-card input{
127147 width: 75%;
128148 padding-left: 0.5em;
129149 border: none;
130150 background-color: peachpuff;
131151 font-size: 1em;
132152 font-family: 'mononoki';
133153 }
134154
135-#new-zine-form input:focus {
155 +.form-card input:focus {
136156 outline-width: 0px;
137157 border-bottom: 1px solid indigo;
138158 }
139159
140-#new-zine-form input[type=submit]{
160 +.form-card input[type=submit]{
141161 width: 100%;
142162 cursor: pointer;
143163 padding: 0.25em;
144164 color: peachpuff;
@@ -147,9 +167,13 @@
147167 color: indigo;
148168 bottom: 0;
149169 }
150170
151-#new-zine-form input[type=submit]:hover{
171 +#new-branch-form.form-card input[type=submit]{
172 + font-size: 24px;
173 +}
174 +
175 +.form-card input[type=submit]:hover{
152176 background-color: lavender;
153177 }
154178
155179 #new-zine-notes{
building/components/actionButtons.jsView
@@ -1,27 +1,43 @@
11 const html = require('nanohtml')
22
33 module.exports = { addZine, makeBranch }
44
5-function addZine () {
6- return html`
5 +function addZine (state) {
6 + if (state.identity === 'librarian') {
7 + return html`
78 <button id='add-button' onclick=${toggleForm}>Add Zine</button>
8- `
9 + `
10 + }
911 }
1012
1113 function makeBranch () {
1214 return html`
13- <button id='branch-button'>Make New Branch</button>
15 + <button id='branch-button' onclick=${toggleBranch}>Make A New Branch</button>
1416 `
1517 }
1618
1719 function toggleForm () {
1820 var addButton = document.getElementById('add-button')
1921 var form = document.getElementById('new-zine-form')
22 +
2023 form.classList.toggle('revealed')
2124
2225 if (addButton.textContent === 'close') {
2326 addButton.textContent = 'Add Zine'
2427 } else {
2528 addButton.textContent = 'close'
2629 }
2730 }
31 +
32 +function toggleBranch () {
33 + var branchButton = document.querySelector('#branch-button')
34 + var form = document.querySelector('#new-branch-form')
35 +
36 + form.classList.toggle('revealed')
37 +
38 + if (branchButton.textContent === 'close') {
39 + branchButton.textContent = 'Make a New Branch!'
40 + } else {
41 + branchButton.textContent = 'close'
42 + }
43 +}
building/components/library.jsView
@@ -2,16 +2,20 @@
22
33 const newZineForm = require('./newZineForm')
44 const shelving = require('./shelving')
55 const button = require('./actionButtons')
6 +const branchPlacard = require('./branchPlacard')
7 +const newBranchForm = require('./newBranchForm')
8 +
69 module.exports = view
710
811 function view (state, emit) {
912 return html`
1013 <body>
11- <h1 id='welcome-title'>Welcome to your Zine Library, Good Friend!</h1>
12- ${button.addZine()}
14 + ${branchPlacard(state, emit)}
15 + ${button.addZine(state)}
1316 ${newZineForm(emit)}
17 + ${newBranchForm()}
1418 ${shelving(state)}
1519 </body>
1620 `
1721 // newZineForm is a button for adding new zines
building/components/newZineForm.jsView
@@ -7,9 +7,9 @@
77 //I would like this to be form validated, but cannot figure out how to
88 // Do so, the regEx pattern matching doesn't seem to work...
99 return html`
1010 <section id='add-zines'>
11- <div id='new-zine-form' class='transition'>
11 + <div id='new-zine-form' class='form-card transition'>
1212 <h1>Add A Zine</h1>
1313 <form onsubmit=${submitZine}>
1414 <label for='title'>Title:
1515 <input id='title' name='title'
building/components/branchPlacard.jsView
@@ -1,0 +1,29 @@
1 +const html = require('nanohtml')
2 +const raw = require('nanohtml/raw')
3 +const md = require('markdown-it')()
4 +
5 +const button = require('./actionButtons')
6 +
7 +module.exports = view
8 +
9 +function view (state, emit) {
10 + if (state.branch.title) {
11 + var branch = state.branch
12 + console.log({branch})
13 + return html`
14 + <section id='branch-placard'>
15 + <h1>${branch.title}</h1>
16 + ${render(branch.description)}
17 + <p>Want to start your own zine library?<span> ${button.makeBranch()}</span></p>
18 + </section>
19 + `
20 + } else {
21 + return html`<h1>loading</h1>`
22 + }
23 +}
24 +
25 +function render (text) {
26 + var htmlFromMarkdown = md.render(text)
27 + var compatibleHTML = raw(htmlFromMarkdown)
28 + return html`<article>${compatibleHTML}</article>`
29 +}
building/components/newBranchForm.jsView
@@ -1,0 +1,27 @@
1 +var html = require('nanohtml')
2 +var choo = require('choo')
3 +
4 +module.exports = view
5 +
6 +function view (emit) {
7 +//I would like this to be form validated, but cannot figure out how to
8 +// Do so, the regEx pattern matching doesn't seem to work...
9 + return html`
10 + <div id='new-branch-form' class='form-card transition'>
11 + <h1>Make a New Branch</h1>
12 + <p>You can make your own copy of this library by clicking the button below. This will open your library in a new tab.</p>
13 + <p>It's best to read the README first, as it guides you through setting up your own zines and customizing the site and such. To get to the README on your new branch, click the three dots in the address bar and then click 'view files'.</p>
14 + <p>Thanks for doing this and have fun!</p>
15 + <input type='submit' value='Make a Branch!' onclick=${makeBranch}/>
16 + </div>
17 + `
18 + async function makeBranch () {
19 + document.querySelector('#new-branch-form').classList.toggle('revealed')
20 + var branchButton = document.querySelector('#branch-button')
21 + branchButton.textContent = 'Make a New Branch!'
22 +
23 + var self = new DatArchive(window.location)
24 + var branch = await DatArchive.fork(self, {title: 'name your branch!', description: 'this description is for beaker, add a longer one in yr distro/ folder'})
25 + window.open(branch.url)
26 + }
27 +}
index.jsView
@@ -3,9 +3,11 @@
33 const library = require('./building/components/library')
44
55 const app = choo()
66
7-//Jobs to be done by the javascript volunteers
8-app.use(require('./volunteers/jobs'))
9-app.use(require('./volunteers/addingZines'))
7 +// Jobs to be done by the javascript volunteers
8 +app.use(require('./volunteers/branchManager'))
9 +app.use(require('./volunteers/addNewZines'))
10 +app.use(require('./volunteers/displayBranchInfo'))
11 +
1012 app.mount('body')
1113 app.route('/', library)
volunteers/addingZines.jsView
@@ -1,31 +1,0 @@
1-const smarkt = require('smarkt')
2-const _ = require('lodash')
3-
4-var archive = new DatArchive(window.location)
5-
6-function store (state, emitter) {
7- emitter.on('zine submitted', function (zineSubmission) {
8- var details = getDetails(zineSubmission)
9- var zineJson = JSON.stringify(details, null, 2)
10- writeZineTxt(zineJson, emitter)
11- })
12-}
13-
14-function getDetails (form) {
15- var formData = new FormData(form)
16- var data = {}
17- for (var pair of formData.entries()) {
18- data[pair[0]] = pair[1]
19- }
20- return data
21-}
22-
23-function writeZineTxt (zine, emitter) {
24- zine = JSON.parse(zine)
25- var fileName = zine.title.replace(/ /g, '-') + '.txt'
26- var pleasantText = smarkt.stringify(zine)
27- archive.writeFile(`zines/${fileName}`, pleasantText)
28- .then(() => emitter.emit('update library', zine))
29-}
30-
31-module.exports = store
volunteers/addNewZines.jsView
@@ -1,0 +1,31 @@
1 +const smarkt = require('smarkt')
2 +const _ = require('lodash')
3 +
4 +var archive = new DatArchive(window.location)
5 +
6 +function store (state, emitter) {
7 + emitter.on('zine submitted', function (zineSubmission) {
8 + var details = getDetails(zineSubmission)
9 + var zineJson = JSON.stringify(details, null, 2)
10 + writeZineTxt(zineJson, emitter)
11 + })
12 +}
13 +
14 +function getDetails (form) {
15 + var formData = new FormData(form)
16 + var data = {}
17 + for (var pair of formData.entries()) {
18 + data[pair[0]] = pair[1]
19 + }
20 + return data
21 +}
22 +
23 +function writeZineTxt (zine, emitter) {
24 + zine = JSON.parse(zine)
25 + var fileName = zine.title.replace(/ /g, '-') + '.txt'
26 + var pleasantText = smarkt.stringify(zine)
27 + archive.writeFile(`zines/${fileName}`, pleasantText)
28 + .then(() => emitter.emit('update library', zine))
29 +}
30 +
31 +module.exports = store
volunteers/jobs.jsView
@@ -1,87 +1,0 @@
1-const smarkt = require('smarkt')
2-const _ = require('lodash')
3-const html = require('nanohtml')
4-
5-
6-var archive = new DatArchive(window.location)
7-
8-function store (state, emitter) {
9- state.library = []
10- state.info = {}
11- state.covers = {}
12- state.identity = ''
13-
14- emitter.on('DOMContentLoaded', function () {
15- setIdentity()
16- archive.readdir('zines')
17- .then(zines => mapToState(zines))
18- })
19-
20- emitter.on('update library', function (zine) {
21- addToLibrary(zine)
22- addZineInfo(zine.url)
23- addZineCover(zine.url)
24- })
25-
26- function mapToState (zines) {
27- zines.map(zine => {
28- archive.readFile(`zines/${zine}`)
29- .then(rawText => {
30- var textJson = smarkt.parse(rawText)
31- addToLibrary(textJson)
32- addZineInfo(textJson.url)
33- addZineCover(textJson.url)
34- })
35- })
36- }
37-
38- function addToLibrary (text) {
39- state.library = [...state.library, text]
40- emitter.emit('pushState')
41- }
42-
43- function addZineInfo (datUrl) {
44- var zine = new DatArchive(datUrl)
45- zine.readFile('distro/info.txt')
46- .then(text => {
47- mapInfoToState(text, zine['url'])
48- })
49- }
50-
51- function addZineCover (datUrl) {
52- var zine = new DatArchive(datUrl)
53- zine.readdir('distro')
54- .then(files => {
55- mapCoverToState(files, zine['url'])
56- })
57- }
58-
59- function mapInfoToState (info, datUrl) {
60- var infoJson = smarkt.parse(info)
61- state.info[datUrl] = infoJson
62- emitter.emit('pushState')
63- }
64-
65- function mapCoverToState (files, datUrl) {
66- var cover = files.find(file => sansExtension(file) === 'cover')
67- state.covers[datUrl] = `${datUrl}/distro/${cover}`
68- emitter.emit('pushState')
69- }
70-
71- async function setIdentity () {
72- var info = await archive.getInfo()
73- if (info.isOwner) {
74- state.identity = 'librarian'
75- emitter.emit('pushState')
76- } else {
77- state.identity = 'visitor'
78- emitter.emit('pushstate')
79- }
80- }
81-}
82-
83-function sansExtension (file) {
84- return file.split('.')[0]
85-}
86-
87-module.exports = store
volunteers/branchManager.jsView
@@ -1,0 +1,87 @@
1 +const smarkt = require('smarkt')
2 +const _ = require('lodash')
3 +const html = require('nanohtml')
4 +
5 +
6 +var archive = new DatArchive(window.location)
7 +
8 +function store (state, emitter) {
9 + state.library = []
10 + state.info = {}
11 + state.covers = {}
12 + state.identity = ''
13 +
14 + emitter.on('DOMContentLoaded', function () {
15 + setIdentity()
16 + archive.readdir('zines')
17 + .then(zines => mapToState(zines))
18 + })
19 +
20 + emitter.on('update library', function (zine) {
21 + addToLibrary(zine)
22 + addZineInfo(zine.url)
23 + addZineCover(zine.url)
24 + })
25 +
26 + function mapToState (zines) {
27 + zines.map(zine => {
28 + archive.readFile(`zines/${zine}`)
29 + .then(rawText => {
30 + var textJson = smarkt.parse(rawText)
31 + addToLibrary(textJson)
32 + addZineInfo(textJson.url)
33 + addZineCover(textJson.url)
34 + })
35 + })
36 + }
37 +
38 + function addToLibrary (text) {
39 + state.library = [...state.library, text]
40 + emitter.emit('pushState')
41 + }
42 +
43 + function addZineInfo (datUrl) {
44 + var zine = new DatArchive(datUrl)
45 + zine.readFile('distro/info.txt')
46 + .then(text => {
47 + mapInfoToState(text, zine['url'])
48 + })
49 + }
50 +
51 + function addZineCover (datUrl) {
52 + var zine = new DatArchive(datUrl)
53 + zine.readdir('distro')
54 + .then(files => {
55 + mapCoverToState(files, zine['url'])
56 + })
57 + }
58 +
59 + function mapInfoToState (info, datUrl) {
60 + var infoJson = smarkt.parse(info)
61 + state.info[datUrl] = infoJson
62 + emitter.emit('pushState')
63 + }
64 +
65 + function mapCoverToState (files, datUrl) {
66 + var cover = files.find(file => sansExtension(file) === 'cover')
67 + state.covers[datUrl] = `${datUrl}/distro/${cover}`
68 + emitter.emit('pushState')
69 + }
70 +
71 + async function setIdentity () {
72 + var info = await archive.getInfo()
73 + if (info.isOwner) {
74 + state.identity = 'librarian'
75 + emitter.emit('pushState')
76 + } else {
77 + state.identity = 'visitor'
78 + emitter.emit('pushstate')
79 + }
80 + }
81 +}
82 +
83 +function sansExtension (file) {
84 + return file.split('.')[0]
85 +}
86 +
87 +module.exports = store
volunteers/displayBranchInfo.jsView
@@ -1,0 +1,17 @@
1 +const smarkt = require('smarkt')
2 +
3 +var archive = new DatArchive(window.location)
4 +
5 +function store (state, emitter) {
6 + state.branch = {}
7 + emitter.on('DOMContentLoaded', function () {
8 + archive.readFile('distro/info.txt')
9 + .then(file => {
10 + var branchInfo = smarkt.parse(file)
11 + state.branch = branchInfo
12 + emitter.emit('pushState')
13 + })
14 + })
15 +}
16 +
17 +module.exports = store
volunteers/setBranchName.jsView
distro/info.txtView
@@ -1,0 +1,9 @@
1 +title: Zach Mandeville's Zine Library
2 +----
3 +description:
4 +
5 +The first dat zine library, but hopefully not the last! Collecting zines I wrote, my friends wrote, and ones that I discovered through sharing on here.
6 +
7 +
8 +**Send me your zine! [webmaster@coolguy.website](mailto:webmaster@coolguy.website) or through [Scuttlebutt](https://scuttlebutt.nz) (where I am Zach!)**
9 +

Built with git-ssb-web