Files: 96337c62e3ddfa9c60cef474a2d2f980e1239221 / message / html / render / about.js
1655 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 } = 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 | |
38 | // TODO : build better normalizers |
39 | if (image && ref.isBlob(image.link)) image = image.link |
40 | about = about || link |
41 | |
42 | const metaData = [ |
43 | when(name, h('div', [ h('strong', 'Name: '), name ])), |
44 | when(description, h('div', [ h('strong', 'Description: '), description ])), |
45 | when(image, h('img', { src: api.blob.sync.url(image) })) |
46 | ] |
47 | |
48 | if (!ref.isFeed(about)) { |
49 | return [ |
50 | 'Describes ', |
51 | h('a', { href: about }, [about.slice(0, 7), '...']), |
52 | ' as: ', |
53 | ...metaData |
54 | ] |
55 | } |
56 | |
57 | const target = author === about |
58 | ? 'themself ' |
59 | : api.about.html.link(about) |
60 | |
61 | return [ |
62 | 'Declares the following about ', target, |
63 | ...metaData |
64 | ] |
65 | } |
66 | } |
67 | |
68 |
Built with git-ssb-web