Files: 6a7ad51c236a5d88863f1dbbd45ee5b6cba6c883 / render.js
1553 bytesRaw
1 | var h = require('hyperscript') |
2 | |
3 | var human = require('human-time') |
4 | var ref = require('ssb-ref') |
5 | var avatar = require('./avatar') |
6 | |
7 | var markdown = require('ssb-markdown') |
8 | var config = require('./config')() |
9 | |
10 | function rawJSON (obj) { |
11 | return JSON.stringify(obj, null, 2) |
12 | .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/) |
13 | .map(function (e) { |
14 | if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) { |
15 | return h('a', {href: '#' + e}, e) |
16 | } |
17 | return e |
18 | }) |
19 | } |
20 | |
21 | module.exports = function (msg) { |
22 | if (msg.value.content.type == 'post') { |
23 | return h('div.message__content', |
24 | h('span.avatar', |
25 | h('a', {href: '#' + msg.value.author}, |
26 | h('span.avatar--small', avatar.image(msg.value.author)), |
27 | avatar.name(msg.value.author) |
28 | ) |
29 | ), |
30 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
31 | h('div.message__body', |
32 | {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) { |
33 | if(!image) return url |
34 | if(url[0] !== '&') return url |
35 | return config.blobsurl + url |
36 | }})} |
37 | ) |
38 | ) |
39 | } else { |
40 | return h('div.message__content', |
41 | h('span.avatar', |
42 | h('a', {href: '#' + msg.value.author}, |
43 | h('span.avatar--small', avatar.image(msg.value.author)), |
44 | avatar.name(msg.value.author) |
45 | ) |
46 | ), |
47 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
48 | h('pre', rawJSON(msg.value.content)) |
49 | ) |
50 | } |
51 | } |
52 |
Built with git-ssb-web