Files: 9cb1f4750ae6c9ff84982b276932f872cc1134cd / tools.js
1844 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 | |
15 | pull( |
16 | sbot.backlinks({query: [{$filter: {dest: msg.key, value: { content: { type: 'vote' }}}}], live: true}), |
17 | pull.drain(function (data) { |
18 | console.log(data) |
19 | if (data.value) { |
20 | votes.appendChild(h('a', {href:'#' + data.key}, h('img.emoji', {src: config.emojiUrl + 'star.png'}))) |
21 | console.log(data) |
22 | } else {console.log(data)} |
23 | }) |
24 | ) |
25 | return votes |
26 | } |
27 | |
28 | module.exports.header = function (msg) { |
29 | return h('div.header', |
30 | h('span.avatar', |
31 | h('a', {href: '#' + msg.value.author}, |
32 | h('span.avatar--small', avatar.image(msg.value.author)), |
33 | avatar.name(msg.value.author) |
34 | ) |
35 | ), |
36 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
37 | votes(msg) |
38 | ) |
39 | } |
40 | |
41 | module.exports.messageLink = function (msglink) { |
42 | var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...')) |
43 | return link |
44 | } |
45 | |
46 | module.exports.rawJSON = function (obj) { |
47 | return JSON.stringify(obj, null, 2) |
48 | .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/) |
49 | .map(function (e) { |
50 | if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) { |
51 | return h('a', {href: '#' + e}, e) |
52 | } |
53 | return e |
54 | }) |
55 | } |
56 | |
57 | var markdown = require('ssb-markdown') |
58 | var config = require('./config')() |
59 | |
60 | module.exports.markdown = function (msg, md) { |
61 | return {innerHTML: markdown.block(msg, {toUrl: function (url, image) { |
62 | if(url[0] == '%' || url[0] == '@') return '#' + url |
63 | if(!image) return url |
64 | if(url[0] !== '&') return url |
65 | return config.blobsUrl + url |
66 | }})} |
67 | } |
68 |
Built with git-ssb-web