git ssb

16+

Dominic / patchbay



Tree: 54379731e6002dd982eab86febf0b7d4872a5ff8

Files: 54379731e6002dd982eab86febf0b7d4872a5ff8 / message / html / render / about.js

1820 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 { name, description, image, about } = msg.value.content
24 if (!name && !description && !image) return
25
26 if (ref.isMsg(about)) return
27
28 const element = api.message.html.layout(msg, extend({
29 content: renderContent(msg),
30 layout: 'default'
31 }, opts))
32
33 return api.message.html.decorate(element, { msg })
34 }
35
36 function renderContent (msg) {
37 const { author, content } = msg.value
38 var { about, link, name, description, image } = content
39 if (!about) return
40
41 // TODO : build better normalizers
42 if (image && ref.isBlob(image.link)) image = image.link
43 about = about || link
44
45 const metaData = [
46 when(name, h('div', [ h('strong', 'Name: '), name ])),
47 when(description, h('div', [ h('strong', 'Description: '), description ])),
48 when(image, h('img', { src: api.blob.sync.url(image), style: { 'margin-top': '.5rem' } }))
49 ]
50
51 if (!ref.isFeed(about)) {
52 return [
53 h('p', [
54 'Describes ',
55 h('a', { href: about }, [about.slice(0, 7), '...']),
56 ' as: '
57 ]),
58 ...metaData
59 ]
60 }
61
62 const target = author === about
63 ? 'themself '
64 : api.about.html.link(about)
65
66 return [
67 h('p', [
68 'Declares the following about ',
69 target
70 ]),
71 ...metaData
72 ]
73 }
74}
75

Built with git-ssb-web