Files: a7f68e1a76889ae73272b63475776b226d864a95 / tools.js
1762 bytesRaw
1 | var h = require('hyperscript') |
2 | var human = require('human-time') |
3 | var avatar = require('./avatar') |
4 | var ref = require('ssb-ref') |
5 | |
6 | var pull = require('pull-stream') |
7 | |
8 | var sbot = require('./scuttlebot') |
9 | |
10 | var config = require('./config')() |
11 | |
12 | function 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 | |
27 | module.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 | |
40 | module.exports.messageLink = function (msglink) { |
41 | var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...')) |
42 | return link |
43 | } |
44 | |
45 | module.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 | |
56 | var markdown = require('ssb-markdown') |
57 | var config = require('./config')() |
58 | |
59 | module.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