index.jsView |
---|
1 | | -var http = require('http'); |
2 | 1 | var client = require('ssb-client'); |
3 | 2 | var pull = require('pull-stream'); |
4 | 3 | var moment = require('moment'); |
5 | | -var h = require('hyperscript'); |
6 | | -var {html, head, body, p, title } = require('hyperscript-helpers')(h); |
| 4 | +var app = require('koa')(); |
| 5 | +var router = require('koa-router')(); |
| 6 | +var views = require('co-views'); |
7 | 7 | |
8 | | -var message; |
9 | 8 | var port = 1337; |
10 | 9 | var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
| 10 | +var message = 'I said nothing'; |
11 | 11 | |
12 | 12 | client(function (err, sbot) { |
13 | 13 | if (err) { |
14 | 14 | throw err; |
18 | 18 | limit: 1, |
19 | 19 | reverse: true |
20 | 20 | }), |
21 | 21 | pull.drain(function printMessage(msg) { |
22 | | - if (msg.value.content.type === 'post') { |
23 | | - message = (msg.value.content.text + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>') |
| 22 | + date = moment(msg.value.timestamp).fromNow() |
| 23 | + if (msg.value.content.type === 'post') { |
| 24 | + message = (msg.value.content.text) |
24 | 25 | } |
25 | | - else if (msg.value.content.type === 'vote') { |
26 | | - message = ('I dug ' + msg.value.content.vote.link + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>') |
| 26 | + else if (msg.value.content.type === 'vote') { |
| 27 | + message = ('I dug ' + msg.value.content.vote.link) |
27 | 28 | } |
28 | | - else if (msg.value.content.type === 'about') { |
29 | | - message = ('I identified ' + msg.value.content.about + ' as ' + msg.value.content.name + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>') |
| 29 | + else if (msg.value.content.type === 'about') { |
| 30 | + message = ('I identified ' + msg.value.content.about + ' as ' + msg.value.content.name) |
30 | 31 | } |
31 | | - else if (msg.value.content.type === 'git-update') { |
32 | | - message = ('I pushed a git commit to <a href="http://gitmx.com/">gitmx.com</a> - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>') |
| 32 | + else if (msg.value.content.type === 'git-update') { |
| 33 | + message = ('I pushed a commit ') |
33 | 34 | } |
34 | | - else { |
35 | | - message = ('I sent a private message - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>') |
| 35 | + else { |
| 36 | + message = ('I sent a private message ') |
36 | 37 | } |
37 | 38 | })); |
38 | | - var site = function () { |
39 | | - var layout = |
40 | | - html( |
41 | | - head( |
42 | | - title('Latest Sbot Post') |
43 | | - ), |
44 | | - body( |
45 | | - p(message) |
46 | | - ) |
47 | | - ); |
48 | | - return layout.outerHTML; |
49 | | - }; |
50 | | - http.createServer(function (req, res) { |
51 | | - res.end(site()); |
52 | | - }).listen(port, function () { |
53 | | - console.log(`Server running at http://localhost:${port}/`); |
| 39 | + app.use(router.routes()) |
| 40 | + app.use(router.allowedMethods()) |
| 41 | + |
| 42 | + var render = views(__dirname, { ext: 'jade'}); |
| 43 | + |
| 44 | + router.get('/', function *(next) { |
| 45 | + this.body = yield render('index', {title: 'sdash', message, date}); |
54 | 46 | }); |
| 47 | + app.listen(port); |
55 | 48 | }); |
56 | 49 | |
57 | | - |
58 | | - |