Commit b1d27bb56f4c964bcfc04597ab5026aaaa9b57d5
add minimal about message
mix irving committed on 4/2/2017, 12:21:34 PMParent: b27c7da727a6667120dbf9108cecbef28faa8060
Files changed
message/html/render/about.js | added |
message/html/render/about.js | ||
---|---|---|
@@ -1,0 +1,56 @@ | ||
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 element = api.message.html.layout(msg, extend({ | |
24 | + content: renderContent(msg), | |
25 | + layout: 'default' | |
26 | + }, opts)) | |
27 | + | |
28 | + return api.message.html.decorate(element, { msg }) | |
29 | + } | |
30 | + | |
31 | + function renderContent (msg) { | |
32 | + const { author, content } = msg.value | |
33 | + const { about, name, description, image } = content | |
34 | + | |
35 | + if (!ref.isFeed(about)) { | |
36 | + return [ | |
37 | + 'Describes ', | |
38 | + h('a', { href: about }, [about.slice(0, 7), '...']), | |
39 | + ' as: ', | |
40 | + name | |
41 | + ] | |
42 | + } | |
43 | + | |
44 | + const target = author === about | |
45 | + ? 'themself ' | |
46 | + : api.about.html.link(about) | |
47 | + | |
48 | + return [ | |
49 | + 'Declares the following about ', target, | |
50 | + when(name, h('div', [ h('strong', 'Name: '), name ])), | |
51 | + when(description, h('div', [ h('strong', 'Description: '), description ])), | |
52 | + when(image, h('img', { src: api.blob.sync.url(image) })) | |
53 | + ] | |
54 | + } | |
55 | +} | |
56 | + |
Built with git-ssb-web