Files: adb12e2137735a611a815b1947491a542fde0e61 / render.js
1295 bytesRaw
1 | var h = require('hyperscript') |
2 | |
3 | var human = require('human-time') |
4 | |
5 | var avatar = require('./avatar') |
6 | |
7 | var markdown = require('ssb-markdown') |
8 | var config = require('./config')() |
9 | |
10 | var rawJSON = require('patchapp-raw/json') |
11 | |
12 | module.exports = function (msg) { |
13 | if (msg.value.content.type == 'post') { |
14 | return h('div.message__content', |
15 | h('span.avatar', |
16 | h('a', {href: '#' + msg.value.author}, |
17 | h('span.avatar--small', avatar.image(msg.value.author)), |
18 | avatar.name(msg.value.author) |
19 | ) |
20 | ), |
21 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
22 | h('div.message__body', |
23 | {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) { |
24 | if(!image) return url |
25 | if(url[0] !== '&') return url |
26 | return config.blobsurl + url |
27 | }})} |
28 | ) |
29 | ) |
30 | } else { |
31 | return h('div.message__content', |
32 | h('span.avatar', |
33 | h('a', {href: '#' + msg.value.author}, |
34 | h('span.avatar--small', avatar.image(msg.value.author)), |
35 | avatar.name(msg.value.author) |
36 | ) |
37 | ), |
38 | h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))), |
39 | h('pre.raw__json', {id: msg.key}, rawJSON(msg)) |
40 | ) |
41 | } |
42 | } |
43 |
Built with git-ssb-web