git ssb

3+

ev / sdash



Commit d5b9ef22f1e78e8a06ae3f3e00ae4ca9a88df3fc

rewrite sdash in hyperscript

Ev Bogue committed on 9/15/2016, 8:43:41 PM
Parent: 6456cf14629c2ebd1c37ca63e36a9b800951a77a

Files changed

index.jschanged
package.jsonchanged
readme.mdchanged
ipmdeleted
layouts/index.jadedeleted
layouts/layout.jadedeleted
layouts/profile.jadedeleted
index.jsView
@@ -1,121 +1,116 @@
1-var express = require('express');
2-var pull = require('pull-stream');
3-var client = require('ssb-client');
4-var avatar = require('ssb-avatar');
5-var markdown = require('marked');
6-var favicon = require('serve-favicon');
7-var moment = require('moment');
1 +var http = require('http')
2 +var fs = require('fs')
3 +var h = require('hyperscript')
4 +var pull = require('pull-stream')
5 +var client = require('ssb-client')
6 +var md = require('ssb-markdown')
7 +var avatar = require('ssb-avatar')
8 +var mo = require('moment')
89
9-var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519';
10 +var title = 'sdash'
11 +var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519'
12 +var desc = 'This is <a href="https://gitmx.com/%25qrU04j9vfUJKfq1rGZrQ5ihtSfA4ilfY3wLy7xFv0xk%3D.sha256">sdash</a>, a work-in-progress personal gateway to the <a href="http://ssbc.github.io">scuttlebot</a> distributed social network'
13 +var bloburl = 'http://localhost:8989/blobs/get/'
1014
11-var bloburl = 'http://localhost:8989/blobs/get/';
1215
13-var app = express();
14-
15-app.set('views', './layouts')
16-app.set('view engine', 'jade');
17-
18-app.use(express.static('static'));
19-app.use(favicon(__dirname + '/static/favicon.ico'));
20-
21-app.get('/:key', function (req, res) {
22- client(function (err, sbot) {
23- if (err) {
24- throw err;
25- }
26- avatar(sbot, me, req.params.key, function (err, avatar){
27- if (err) {
28- throw err;
29- }
30- key = req.params.key;
31- pull(
32- sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'post'}}}}], limit: 1, reverse: true}),
33- pull.drain(function (data) {
34- post = data;
35- })
36- )
37- pull(
38- sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'tagline'}}}}], limit: 1, reverse: true}),
39- pull.drain(function (data) {
40- tagline = data;
41- console.log(tagline)
42- })
43- )
44- pull(
45- sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'location'}}}}], limit: 1, reverse: true}),
46- pull.drain(function (data) {
47- loc = data;
48- console.log(loc)
49- })
50- )
51- pull(
52- sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'website'}}}}], limit: 1, reverse: true}),
53- pull.drain(function (data) {
54- website = data;
55- console.log(website)
56- })
57- )
58- res.render('profile', {avatar, bloburl, key, markdown, moment});
59- })
60- })
61-});
62-
63-app.get('/', function (req, res) {
64- client(function (err, sbot) {
65- if (err) {
66- throw err;
67- }
68- avatar(sbot, me, me, function (err, avatar){
69- if (err) {
70- throw err;
71- }
72- name = avatar.name;
73- image = avatar.image;
16 +http.createServer(function (req, res){
17 + if (req.url === '/') {
18 + client(function (err, sbot) {
19 + avatar(sbot, me, me, function (err, avatar){
20 + if (err) {
21 + throw err;
22 + }
23 + name = avatar.name;
24 + image = avatar.image;
25 + })
26 + pull(
27 + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}),
28 + pull.drain(function (data) {
29 + post = data
30 + })
31 + )
32 + pull(
33 + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}),
34 + pull.drain(function (data) {
35 + getpin = data;
36 + pull(
37 + sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}),
38 + pull.drain(function (data) {
39 + pinned = data;
40 + gotPost()
41 + })
42 + )
43 + })
44 + )
45 + pull(
46 + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}),
47 + pull.drain(function (data) {
48 + vote = data;
49 + pull(
50 + sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}),
51 + pull.drain(function (reblog) {
52 + avatar(sbot, me, reblog.value.author, function (err, avatar){
53 + if (err) {
54 + throw err;
55 + }
56 + reauthor = avatar;
57 + })
58 + redo = reblog;
59 + })
60 + )
61 + })
62 + )
63 + pull(
64 + sbot.query.read({query: [{$filter: { value: { content: {mentions: [{link: me}]}}}}], limit: 1, reverse: true}),
65 + pull.drain(function (data) {
66 + mention = data
67 + })
68 + )
69 + pull(
70 + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}),
71 + pull.drain(function (data) {
72 + gits = data
73 + })
74 + )
75 +
7476 })
75- pull(
76- sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}),
77- pull.drain(function (data) {
78- getpin = data;
79- pull(
80- sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}),
81- pull.drain(function (data) {
82- pinned = data;
83- })
77 + function gotPost() {
78 + res.end(
79 + h('html',
80 + h('head',
81 + h('title', title),
82 + h('style', fs.readFileSync('style.css', 'utf8'))
83 + ),
84 + h('body',
85 + h('img.profile', {src: bloburl + image}),
86 + h('h1',
87 + h('a', {href: me }, '@' + name)
88 + ),
89 + h('p', {innerHTML: desc}),
90 + h('hr'),
91 + h('div.msg',
92 + h('p.small.ri', 'pinned'),
93 + h('img.avatar', {src: bloburl + image}),
94 + h('div', {innerHTML: md.block(pinned.value.content.text)},
95 + h('span.date', mo(pinned.value.timestamp).fromNow())
96 + )
97 + ),
98 + h('div.msg',
99 + h('p.small.ri', 'post'),
100 + h('img.avatar', {src: bloburl + image}),
101 + h('div', {innerHTML: md.block(post.value.content.text)},
102 + h('span.date', mo(post.value.timestamp).fromNow())
103 + )
104 + ),
105 + h('div.msg',
106 + h('p.small.ri', 'dig'),
107 + h('img.avatar', {src: bloburl + image}),
108 + h('div', vote.value.content.vote.link,
109 + h('span.date', mo(vote.value.timestamp).fromNow())
110 + )
111 + )
84112 )
85- })
86- )
87- pull(
88- sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}),
89- pull.drain(function (data) {
90- post = data;
91- })
92- )
93- pull(
94- sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}),
95- pull.drain(function (data) {
96- vote = data;
97- pull(
98- sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}),
99- pull.drain(function (reblog) {
100- avatar(sbot, me, reblog.value.author, function (err, avatar){
101- if (err) {
102- throw err;
103- }
104- reauthor = avatar;
105- })
106- redo = reblog;
107- })
108- )
109- })
110- )
111- pull(
112- sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}),
113- pull.drain(function (data) {
114- gits = data;
115- })
116- )
117- });
118- res.render('index', { title: 'Sdash', markdown, moment, bloburl});
119-});
120-
121-app.listen('7000');
113 + ).outerHTML)
114 + }
115 + }
116 +}).listen(1337)
package.jsonView
@@ -1,17 +1,15 @@
11 {
22 "name": "sdash",
3- "version": "1.1.0",
4- "description": "express app for grabbing sbot posts and tossing them onto your site",
3 + "version": "2.0.0",
4 + "description": "personal gateway to the scuttlebot distributed social network",
55 "main": "index.js",
66 "dependencies": {
7- "express": "^4.14.0",
8- "jade": "^1.11.0",
9- "marked": "^0.3.6",
10- "moment": "^2.14.1",
11- "pull-stream": "^3.4.3",
12- "serve-favicon": "^2.3.0",
7 + "hyperscript": "^2.0.2",
8 + "moment": "^2.15.0",
9 + "pull-stream": "^3.4.5",
1310 "ssb-avatar": "^0.1.0",
14- "ssb-client": "^4.0.3"
11 + "ssb-client": "^4.0.3",
12 + "ssb-markdown": "^3.0.0"
1513 },
1614 "author": "Ev Bogue"
1715 }
readme.mdView
@@ -1,7 +1,7 @@
11 # sdash
22
3-sdash is a simple personal gateway to the [scuttlebot](http://scuttlebot.io) distributed social database
3 +sdash is a personal gateway to the [scuttlebot](http://scuttlebot.io) distributed social network
44
55 ### Install Scuttlebot
66
77 ```
ipmView
@@ -1,5 +1,0 @@
1-# /bin/sh
2-
3-git clone ssb://%Ke2Mke1FhW1WADBXeY1Rxw02C8070tCYldtc68H1pUg=.sha256 static/reserva
4-git clone ssb://%XoC0EPXVomSYODRk0g9w6iGuD/vPCjinTVVW6Dz1hEQ=.sha256 static/ssp
5-
layouts/index.jadeView
@@ -1,40 +1,0 @@
1-extends layout
2-
3-block content
4- if pinned
5- div.message
6- p.small.ri: strong pinned #{pinned.value.content.type}
7- img(src='#{bloburl}#{image}' class='avatar')
8- p <a href='#{encodeURIComponent(pinned.value.author)}' target='_parent'>@#{name}</a>
9- != markdown(pinned.value.content.text)
10- span.date #{moment(pinned.value.timestamp).fromNow()}
11- if (pinned.value.content.channel)
12- span in ##{pinned.value.content.channel}
13- div.message
14- if post
15- p.small.ri: strong #{post.value.content.type}
16- img(src='#{bloburl}#{image}' class='avatar')
17- p <a href='#{encodeURIComponent(post.value.author)}' target='_parent'>@#{name}</a>
18- != markdown(post.value.content.text)
19- span.date #{moment(post.value.timestamp).fromNow()}
20- div.message
21- if vote
22- p.small.ri: strong #{vote.value.content.type}
23- img(src='#{bloburl}#{image}' class='avatar')
24- p <a href='#{encodeURIComponent(vote.value.author)}' target='_parent'>@#{name}</a> dug #{vote.value.content.vote.link}
25- span.date #{moment(vote.value.timestamp).fromNow()}
26- if redo.value.type === post
27- div.message
28- p.small.ri: strong #{redo.value.content.type}
29- img(src='#{bloburl}#{reauthor.image}' class='avatar')
30- p @<a href='#{encodeURIComponent(redo.value.author)}'>#{reauthor.name}</a>
31- != markdown(redo.value.content.text)
32- span.date #{moment(redo.value.timestamp).fromNow()}
33- div.message
34- if gits
35- p.small.ri: strong #{gits.value.content.type}
36- img(src='#{bloburl}#{image}' class='avatar')
37- p <a href='#{encodeURIComponent(gits.value.author)}' target='_parent'>@#{name}</a> pushed a git commit to #{gits.value.content.repo}<br />
38- span.date #{moment(gits.value.timestamp).fromNow()}
39- hr
40- p This is <a href='http://gitmx.com/%25qrU04j9vfUJKfq1rGZrQ5ihtSfA4ilfY3wLy7xFv0xk%3D.sha256/'>sdash</a>
layouts/layout.jadeView
@@ -1,12 +1,0 @@
1-doctype html
2-html
3- head
4- title= title
5- meta(charset='utf8')
6- link(rel='stylesheet' href='/reserva/reserva.css')
7- link(rel='stylesheet' href='/ssp/ssp.css')
8- link(rel='stylesheet' href='/sdash.css')
9- body
10- .contain
11- .eight.col.off-two
12- block content
layouts/profile.jadeView
@@ -1,20 +1,0 @@
1-extends layout
2-
3-block content
4- div.message
5- a(href='/#{key}'): img(src='http://localhost:8989/blobs/get/#{avatar.image}' style='width: 5em; float: left; margin-right: 1em;' class='profile')
6- p <strong>Name:</strong> <a href='/#{key}'>@#{avatar.name}</a><br /><strong>Pubkey:</strong> #{key}
7- if tagline
8- span <br /><strong>Tagline:</strong> #{tagline.value.content.tagline}</a>
9- if loc
10- span <br /><strong>Location:</strong> #{loc.value.content.location}</a>
11- if website
12- span <br /><strong>Website:</strong> <a href='#{website.value.content.text}'>#{website.value.content.website}</a>
13-
14- div.message
15- p.small.ri: strong last #{post.value.content.type}
16- img(src='#{bloburl}#{avatar.image}' class='avatar')
17- p <a href='#{post.value.key}' target='_parent'>@#{avatar.name}</a>
18- != markdown(post.value.content.text)
19- span.date #{moment(post.value.timestamp).fromNow()}
20-

Built with git-ssb-web