git ssb

3+

ev / sdash



Commit 432812d2ffd6179f54adef34d943ffc0475a63d0

rewrite sdash in hyperscript

Ev Bogue committed on 8/13/2016, 12:40:31 AM
Parent: dbc84320cbc05f6e74a471cc96a95d7889bed434

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -1,54 +1,58 @@
1-var app = require('koa')(),
2- router = require('koa-router')(),
3- views = require('co-views'),
4- serve = require('koa-static');
5-
1 +var http = require('http');
62 var client = require('ssb-client');
73 var pull = require('pull-stream');
84 var moment = require('moment');
9-var fs = require('fs');
5 +var h = require('hyperscript');
6 +var {html, head, body, p, title } = require('hyperscript-helpers')(h);
107
11-function getSbot () { client(function (err, sbot) {
12- if (err) {
13- throw err;
14- }
15- pull(sbot.createUserStream({
16- id: '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519',
17- limit: 1,
18- reverse: true
19- }),
20- pull.drain(function printMessage(msg) {
21- if (msg.value.content.type === 'post') {
22- var message = (msg.value.content.text + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>')
23- }
24- else if (msg.value.content.type === 'vote') {
25- var message = ('I dug ' + msg.value.content.vote.link + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>')
26- }
27- else if (msg.value.content.type === 'about') {
28- var message = ('I identified ' + msg.value.content.about + ' as ' + msg.value.content.name + ' - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>')
29- }
30- else if (msg.value.content.type === 'git-update') {
31- var 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- }
33- else {
34- var message = ('I sent a private message - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>')
35- }
36- fs.writeFileSync('message.md', message);
37- console.log(message);
38- }));
8 +var message;
9 +var port = 1337;
10 +var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519'
11 +
12 +client(function (err, sbot) {
13 + if (err) {
14 + throw err;
15 + }
16 + pull(sbot.createUserStream({
17 + id: me,
18 + limit: 1,
19 + reverse: true
20 + }),
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>')
24 + }
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>')
27 + }
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>')
30 + }
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>')
33 + }
34 + else {
35 + message = ('I sent a private message - <span class="date">' + moment(msg.value.timestamp).fromNow() + '</span>')
36 + }
37 + }));
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}/`);
54 + });
3955 });
40-};
4156
4257
43-app.use(router.routes())
44-app.use(router.allowedMethods())
4558
46-var render = views(__dirname + '/views', { ext: 'jade'});
47-
48-router.get('/', function *(next) {
49- getSbot();
50- this.body = yield render('index', {title: 'sdash'});
51-});
52-
53-app.listen('4000')
54-
package.jsonView
@@ -1,19 +1,13 @@
11 {
2- "name": "gwenbell.com",
2 + "name": "sdash",
33 "version": "0.0.1",
4- "description": "Gwen Bell's website",
4 + "description": "grab your latest sbot post and put it on your website using an iFrame",
55 "main": "index.js",
66 "dependencies": {
7- "co-views": "",
8- "jade": "",
9- "koa": "",
10- "koa-body-parser": "",
11- "koa-logger": "",
12- "koa-router": "",
13- "koa-static": "^2.0.0",
7 + "hyperscript": "^1.4.7",
8 + "hyperscript-helpers": "^3.0.0",
149 "moment": "^2.14.1",
15- "nodemailer": "",
1610 "pull-stream": "^3.4.3",
1711 "ssb-client": "^4.0.3"
1812 },
1913 "author": "Ev Bogue"

Built with git-ssb-web