git ssb

1+

bencevans / ssb-news



Commit bb1d879ac72e9462c12547ce70a4ccba104a1066

publish through web

Ben Evans committed on 11/7/2018, 6:28:52 PM
Parent: 1e2edf103e55e31d814bbf72b7232bdfe92b346e

Files changed

package.jsonchanged
src/index.jschanged
src/server.jschanged
src/views/new.jschanged
package.jsonView
@@ -7,10 +7,12 @@
77 "doc": "docs"
88 },
99 "dependencies": {
1010 "async": "^2.6.1",
11 + "body": "^5.1.0",
1112 "choo": "^6.13.1",
1213 "choo-devtools": "^2.5.1",
14 + "debug": "^4.1.0",
1315 "electron": "^3.0.7",
1416 "is-url": "^1.2.4",
1517 "minimist": "^1.2.0",
1618 "s-ago": "^2.0.1",
@@ -19,10 +21,14 @@
1921 "ssb-feed": "^2.3.0",
2022 "ssb-names": "^3.1.3",
2123 "tachyons": "^4.10.0"
2224 },
23- "devDependencies": {},
25 + "devDependencies": {
26 + "supervisor": "^0.12.0"
27 + },
2428 "scripts": {
29 + "start": "node src/cli server",
30 + "dev": "DEBUG=* supervisor -- src/cli server",
2531 "test": "echo \"Error: no test specified\" && exit 1"
2632 },
2733 "repository": {
2834 "type": "git",
src/index.jsView
@@ -1,4 +1,5 @@
1 +const debug = require('debug')('ssb-news')
12 const pull = require('pull-stream')
23 const isUrl = require('is-url')
34
45 module.exports = class SSBNews {
@@ -18,8 +19,9 @@
1819 )
1920 }
2021
2122 story (id, cb) {
23 + debug('story', id)
2224 this.sbot.get(id, cb)
2325 }
2426
2527 publish (story, cb) {
src/server.jsView
@@ -2,8 +2,9 @@
22 const app = require('./main')
33 const SSBNews = require('.')
44 const async = require('async')
55 const getUserAbout = require('./helpers/get-user-about')
6 +const body = require('body/form')
67
78 module.exports = function createServer (sbot) {
89 const state = {
910 recent: [],
@@ -44,8 +45,16 @@
4445 const dom = app.toString(req.url, Object.assign({}, state, { story }))
4546 res.end(dom)
4647 })
4748 })
49 + } else if (req.method === 'POST' && req.url === '/new') {
50 + body(req, (err, form) => {
51 + if (err) { throw err }
52 + news.publish(form, (err, msg) => {
53 + if (err) throw err
54 + res.end(msg.key)
55 + })
56 + })
4857 } else {
4958 const dom = app.toString(req.url, state)
5059 res.end(dom)
5160 }
src/views/new.jsView
@@ -1,8 +1,8 @@
11 const html = require('choo/html')
22 const header = require('./header')
33
4-module.exports = function newView () {
4 +module.exports = function newView (state) {
55 return html`
66 <body class="sans-serif">
77
88 <link rel="stylesheet" href="https://unpkg.com/reset-css@4.0.1/reset.css"/>
@@ -20,27 +20,27 @@
2020
2121 }
2222 </style>
2323
24- ${header()}
24 + ${header(state)}
2525
26- <form class="pa4 black-80">
26 + <form class="pa4 black-80" method="POST">
2727 <div class="measure-narrow">
2828 <label for="password" class="f6 b db mb2">Title</label>
29- <input class="input-reset ba b--black-20 pa2 mb2 db w-100" name="q" type="search" id="search" aria-describedby="password-desc" autofocus>
29 + <input class="input-reset ba b--black-20 pa2 mb2 db w-100" name="title" type="text" id="search" aria-describedby="password-desc" autofocus>
3030 <!--<small id="password-desc" class="f6 lh-copy black-60 db mb2">advanced controls include domain:github.com</small>-->
3131 </div>
3232 <div class="measure-narrow">
3333 <label for="password" class="f6 b db mb2">URL</label>
34- <input class="input-reset ba b--black-20 pa2 mb2 db w-100" name="q" type="search" id="search" aria-describedby="password-desc">
34 + <input class="input-reset ba b--black-20 pa2 mb2 db w-100" name="link" type="url" id="search" aria-describedby="password-desc">
3535 <small id="password-desc" class="f6 lh-copy black-60 db mb2">
3636 ... or ...
3737 </small>
3838 </div>
3939
4040 <div class="measure-narrow">
4141 <label for="password" class="f6 b db mb2">Content</label>
42- <textarea class="input-reset ba b--black-20 pa2 mb2 db w-100" name="q" type="search" id="search" aria-describedby="password-desc"></textarea>
42 + <textarea class="input-reset ba b--black-20 pa2 mb2 db w-100" name="body" type="text" id="search" aria-describedby="password-desc"></textarea>
4343 <small id="password-desc" class="f6 lh-copy black-60 db mb2">
4444 markdown?
4545 </small>
4646 </div>

Built with git-ssb-web