git ssb

2+

ev / mvd



Tree: e05454ed7ada31342abbdd6f4b904720bf675270

Files: e05454ed7ada31342abbdd6f4b904720bf675270 / tools.js

1762 bytesRaw
1var h = require('hyperscript')
2var human = require('human-time')
3var avatar = require('./avatar')
4var ref = require('ssb-ref')
5
6var pull = require('pull-stream')
7
8var sbot = require('./scuttlebot')
9
10var config = require('./config')()
11
12function votes (msg) {
13 var votes = h('div.votes')
14 if (msg.key) {
15 pull(
16 sbot.links({dest: msg.key, rel: 'vote'}),
17 pull.drain(function (data) {
18 if (data) {
19 votes.appendChild(h('a', {href:'#' + data.key}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
20 } else {console.log(data)}
21 })
22 )
23 }
24 return votes
25}
26
27module.exports.header = function (msg) {
28 return h('div.header',
29 h('span.avatar',
30 h('a', {href: '#' + msg.value.author},
31 h('span.avatar--small', avatar.image(msg.value.author)),
32 avatar.name(msg.value.author)
33 )
34 ),
35 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
36 votes(msg)
37 )
38}
39
40module.exports.messageLink = function (msglink) {
41 var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...'))
42 return link
43}
44
45module.exports.rawJSON = function (obj) {
46 return JSON.stringify(obj, null, 2)
47 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
48 .map(function (e) {
49 if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) {
50 return h('a', {href: '#' + e}, e)
51 }
52 return e
53 })
54}
55
56var markdown = require('ssb-markdown')
57var config = require('./config')()
58
59module.exports.markdown = function (msg, md) {
60 return {innerHTML: markdown.block(msg, {toUrl: function (url, image) {
61 if(url[0] == '%' || url[0] == '@') return '#' + url
62 if(!image) return url
63 if(url[0] !== '&') return url
64 return config.blobsUrl + url
65 }})}
66}
67

Built with git-ssb-web