Files: bc574122903c7ef4a0abf0fb4918a12a4e96a977 / message / html / render / about.js
1943 bytesRaw
1 | const nest = require('depnest') |
2 | const extend = require('xtend') |
3 | const ref = require('ssb-ref') |
4 | const { h } = 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 | typeof name === 'string' |
47 | ? h('div', [ h('strong', 'Name: '), name ]) |
48 | : undefined, |
49 | typeof description === 'string' |
50 | ? h('div', [ h('strong', 'Description: '), description ]) |
51 | : undefined, |
52 | typeof image === 'string' |
53 | ? h('img', { src: api.blob.sync.url(image), style: { 'margin-top': '.5rem' } }) |
54 | : undefined |
55 | ] |
56 | |
57 | if (!ref.isFeed(about)) { |
58 | return [ |
59 | h('p', [ |
60 | 'Describes ', |
61 | h('a', { href: about }, [about.slice(0, 7), '...']), |
62 | ' as: ' |
63 | ]), |
64 | ...metaData |
65 | ] |
66 | } |
67 | |
68 | const target = author === about |
69 | ? 'themself ' |
70 | : api.about.html.link(about) |
71 | |
72 | return [ |
73 | h('p', [ |
74 | 'Declares the following about ', |
75 | target |
76 | ]), |
77 | ...metaData |
78 | ] |
79 | } |
80 | } |
81 |
Built with git-ssb-web