Commit bb1d879ac72e9462c12547ce70a4ccba104a1066
publish through web
Ben Evans committed on 11/7/2018, 6:28:52 PMParent: 1e2edf103e55e31d814bbf72b7232bdfe92b346e
Files changed
package.json | changed |
src/index.js | changed |
src/server.js | changed |
src/views/new.js | changed |
package.json | ||
---|---|---|
@@ -7,10 +7,12 @@ | ||
7 | 7 … | "doc": "docs" |
8 | 8 … | }, |
9 | 9 … | "dependencies": { |
10 | 10 … | "async": "^2.6.1", |
11 … | + "body": "^5.1.0", | |
11 | 12 … | "choo": "^6.13.1", |
12 | 13 … | "choo-devtools": "^2.5.1", |
14 … | + "debug": "^4.1.0", | |
13 | 15 … | "electron": "^3.0.7", |
14 | 16 … | "is-url": "^1.2.4", |
15 | 17 … | "minimist": "^1.2.0", |
16 | 18 … | "s-ago": "^2.0.1", |
@@ -19,10 +21,14 @@ | ||
19 | 21 … | "ssb-feed": "^2.3.0", |
20 | 22 … | "ssb-names": "^3.1.3", |
21 | 23 … | "tachyons": "^4.10.0" |
22 | 24 … | }, |
23 | - "devDependencies": {}, | |
25 … | + "devDependencies": { | |
26 … | + "supervisor": "^0.12.0" | |
27 … | + }, | |
24 | 28 … | "scripts": { |
29 … | + "start": "node src/cli server", | |
30 … | + "dev": "DEBUG=* supervisor -- src/cli server", | |
25 | 31 … | "test": "echo \"Error: no test specified\" && exit 1" |
26 | 32 … | }, |
27 | 33 … | "repository": { |
28 | 34 … | "type": "git", |
src/index.js | ||
---|---|---|
@@ -1,4 +1,5 @@ | ||
1 … | +const debug = require('debug')('ssb-news') | |
1 | 2 … | const pull = require('pull-stream') |
2 | 3 … | const isUrl = require('is-url') |
3 | 4 … | |
4 | 5 … | module.exports = class SSBNews { |
@@ -18,8 +19,9 @@ | ||
18 | 19 … | ) |
19 | 20 … | } |
20 | 21 … | |
21 | 22 … | story (id, cb) { |
23 … | + debug('story', id) | |
22 | 24 … | this.sbot.get(id, cb) |
23 | 25 … | } |
24 | 26 … | |
25 | 27 … | publish (story, cb) { |
src/server.js | ||
---|---|---|
@@ -2,8 +2,9 @@ | ||
2 | 2 … | const app = require('./main') |
3 | 3 … | const SSBNews = require('.') |
4 | 4 … | const async = require('async') |
5 | 5 … | const getUserAbout = require('./helpers/get-user-about') |
6 … | +const body = require('body/form') | |
6 | 7 … | |
7 | 8 … | module.exports = function createServer (sbot) { |
8 | 9 … | const state = { |
9 | 10 … | recent: [], |
@@ -44,8 +45,16 @@ | ||
44 | 45 … | const dom = app.toString(req.url, Object.assign({}, state, { story })) |
45 | 46 … | res.end(dom) |
46 | 47 … | }) |
47 | 48 … | }) |
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 … | + }) | |
48 | 57 … | } else { |
49 | 58 … | const dom = app.toString(req.url, state) |
50 | 59 … | res.end(dom) |
51 | 60 … | } |
src/views/new.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 … | const html = require('choo/html') |
2 | 2 … | const header = require('./header') |
3 | 3 … | |
4 | -module.exports = function newView () { | |
4 … | +module.exports = function newView (state) { | |
5 | 5 … | return html` |
6 | 6 … | <body class="sans-serif"> |
7 | 7 … | |
8 | 8 … | <link rel="stylesheet" href="https://unpkg.com/reset-css@4.0.1/reset.css"/> |
@@ -20,27 +20,27 @@ | ||
20 | 20 … | |
21 | 21 … | } |
22 | 22 … | </style> |
23 | 23 … | |
24 | - ${header()} | |
24 … | + ${header(state)} | |
25 | 25 … | |
26 | - <form class="pa4 black-80"> | |
26 … | + <form class="pa4 black-80" method="POST"> | |
27 | 27 … | <div class="measure-narrow"> |
28 | 28 … | <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> | |
30 | 30 … | <!--<small id="password-desc" class="f6 lh-copy black-60 db mb2">advanced controls include domain:github.com</small>--> |
31 | 31 … | </div> |
32 | 32 … | <div class="measure-narrow"> |
33 | 33 … | <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"> | |
35 | 35 … | <small id="password-desc" class="f6 lh-copy black-60 db mb2"> |
36 | 36 … | ... or ... |
37 | 37 … | </small> |
38 | 38 … | </div> |
39 | 39 … | |
40 | 40 … | <div class="measure-narrow"> |
41 | 41 … | <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> | |
43 | 43 … | <small id="password-desc" class="f6 lh-copy black-60 db mb2"> |
44 | 44 … | markdown? |
45 | 45 … | </small> |
46 | 46 … | </div> |
Built with git-ssb-web