git ssb

0+

ev / mvp



Tree: 46ef9e90772ab5e16ae211a9cfab1ea45fcaa806

Files: 46ef9e90772ab5e16ae211a9cfab1ea45fcaa806 / tools.js

1186 bytesRaw
1var h = require('hyperscript')
2var human = require('human-time')
3var ref = require('ssb-ref')
4
5var markdown = require('ssb-markdown')
6var config = require('./config')()
7
8module.exports.timestamp = function (msg, edited) {
9 var timestamp = h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp))))
10 return timestamp
11}
12
13module.exports.header = function (msg) {
14 var header = h('div.header')
15
16 header.appendChild(h('span.avatar',
17 h('a', {href: '#' + msg.value.author},
18 msg.value.author
19 )
20 )
21 )
22
23 header.appendChild(exports.timestamp(msg))
24 return header
25}
26
27module.exports.rawJSON = function (obj) {
28 return JSON.stringify(obj, null, 2)
29 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
30 .map(function (e) {
31 if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) {
32 return h('a', {href: '#' + e}, e)
33 }
34 return e
35 })
36}
37
38
39module.exports.markdown = function (msg, md) {
40 return {innerHTML: markdown.block(msg, {toUrl: function (url, image) {
41 if(url[0] == '%' || url[0] == '@') return '#' + url
42 if(!image) return url
43 if(url[0] !== '&') return url
44 return config.blobsUrl + url
45 }})}
46}
47

Built with git-ssb-web