git ssb

16+

Dominic / patchbay



Tree: 905df22ab68b63477bb10099aff3b6d0c8ef9f09

Files: 905df22ab68b63477bb10099aff3b6d0c8ef9f09 / message / html / render / about.js

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

Built with git-ssb-web