Files: 3cad5143f2dc9a45deeb67243d119adf12287420 / message / html / render / about.js
1820 bytesRaw
1 | const nest = require('depnest') |
2 | const extend = require('xtend') |
3 | const ref = require('ssb-ref') |
4 | const { h, when } = require('mutant') |
5 | |
6 | exports.gives = nest('message.html.render') |
7 | |
8 | exports.needs = nest({ |
9 | 'about.html.link': 'first', |
10 | 'blob.sync.url': 'first', |
11 | 'message.html': { |
12 | decorate: 'reduce', |
13 | layout: 'first' |
14 | } |
15 | }) |
16 | |
17 | exports.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