var h = require('hyperscript') var human = require('human-time') var ref = require('ssb-ref') var markdown = require('ssb-markdown') var config = require('./config')() module.exports.timestamp = function (msg, edited) { var timestamp = h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))) return timestamp } module.exports.header = function (msg) { var header = h('div.header') header.appendChild(h('span.avatar', h('a', {href: '#' + msg.value.author}, msg.value.author ) ) ) header.appendChild(exports.timestamp(msg)) return header } module.exports.rawJSON = function (obj) { return JSON.stringify(obj, null, 2) .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/) .map(function (e) { if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) { return h('a', {href: '#' + e}, e) } return e }) } module.exports.markdown = function (msg, md) { return {innerHTML: markdown.block(msg, {toUrl: function (url, image) { if(url[0] == '%' || url[0] == '@') return '#' + url if(!image) return url if(url[0] !== '&') return url return config.blobsUrl + url }})} }