git ssb

16+

Dominic / patchbay



Tree: 85e7dfc62d7132231fe48fc18a0202c70b3e9d7a

Files: 85e7dfc62d7132231fe48fc18a0202c70b3e9d7a / message / html / render / about.js

1492 bytesRaw
1const nest = require('depnest')
2const extend = require('xtend')
3const ref = require('ssb-ref')
4const { h, when } = require('mutant')
5
6exports.gives = nest('message.html.render')
7
8exports.needs = nest({
9 'about.html.link': 'first',
10 'blob.sync.url': 'first',
11 'message.html': {
12 decorate: 'reduce',
13 layout: 'first'
14 }
15})
16
17exports.create = function (api) {
18 return nest('message.html.render', about)
19
20 function about (msg, opts) {
21 if (msg.value.content.type !== 'about') return
22
23 const element = api.message.html.layout(msg, extend({
24 content: renderContent(msg),
25 layout: 'default'
26 }, opts))
27
28 return api.message.html.decorate(element, { msg })
29 }
30
31 function renderContent (msg) {
32 const { author, content } = msg.value
33 var { about, link, name, description, image } = content
34
35 // TODO : build better normalizers
36 if (image && ref.isBlob(image.link)) image = image.link
37 about = about || link
38
39 if (!ref.isFeed(about)) {
40 return [
41 'Describes ',
42 h('a', { href: about }, [about.slice(0, 7), '...']),
43 ' as: ',
44 name
45 ]
46 }
47
48 const target = author === about
49 ? 'themself '
50 : api.about.html.link(about)
51
52 return [
53 'Declares the following about ', target,
54 when(name, h('div', [ h('strong', 'Name: '), name ])),
55 when(description, h('div', [ h('strong', 'Description: '), description ])),
56 when(image, h('img', { src: api.blob.sync.url(image) }))
57 ]
58 }
59}
60
61

Built with git-ssb-web