Files: 75a88ef69dff48f8857d5a63d03c413d76c52ce1 / tools.js
1274 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 | module.exports.header = function (msg) { |
7 | return h('div.header', |
8 | h('span.avatar', |
9 | h('a', {href: '#' + msg.value.author}, |
10 | h('span.avatar--small', avatar.image(msg.value.author)), |
11 | avatar.name(msg.value.author) |
12 | ) |
13 | ), |
14 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
15 | ) |
16 | } |
17 | |
18 | module.exports.messageLink = function (msglink) { |
19 | var link = h('span', h('a', {href: '#' + msglink}, msglink.substring(0, 8) + '...')) |
20 | return link |
21 | } |
22 | |
23 | module.exports.rawJSON = function (obj) { |
24 | return JSON.stringify(obj, null, 2) |
25 | .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/) |
26 | .map(function (e) { |
27 | if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) { |
28 | return h('a', {href: '#' + e}, e) |
29 | } |
30 | return e |
31 | }) |
32 | } |
33 | |
34 | var markdown = require('ssb-markdown') |
35 | var config = require('./config')() |
36 | |
37 | module.exports.markdown = function (msg, md) { |
38 | return {innerHTML: markdown.block(msg, {toUrl: function (url, image) { |
39 | if(url[0] == '%' || url[0] == '@') return '#' + url |
40 | if(!image) return url |
41 | if(url[0] !== '&') return url |
42 | return config.blobsUrl + url |
43 | }})} |
44 | } |
45 |
Built with git-ssb-web