Files: b4a12543a07fd041ced6d5f8589af61a578fc331 / modules_basic / about.js
1458 bytesRaw
1 | var h = require('../h') |
2 | |
3 | //var blob_url = require('../plugs').first(exports.blob_url = []) |
4 | |
5 | exports.needs = { |
6 | blob_url: 'first' |
7 | } |
8 | |
9 | exports.gives = { |
10 | mcss: true, |
11 | message_content: true |
12 | } |
13 | |
14 | var mcss = ` |
15 | About { |
16 | display: flex |
17 | flex-wrap: wrap |
18 | |
19 | header { |
20 | margin-right: .4rem |
21 | } |
22 | } |
23 | ` |
24 | |
25 | exports.create = function (api) { |
26 | return { |
27 | message_content, |
28 | mcss: function () { return mcss } |
29 | } |
30 | |
31 | function message_content (msg) { |
32 | if(msg.value.content.type !== 'about') return |
33 | |
34 | var about = msg.value.content |
35 | var { about: aboutId, name, image, description } = about |
36 | |
37 | // if(!image && !name) return |
38 | |
39 | return h('div', {className: 'About'}, [ |
40 | verb({ aboutId, authorId: msg.value.author }), |
41 | profile({ aboutId, name, image, description, api }) |
42 | ]) |
43 | } |
44 | } |
45 | |
46 | |
47 | function verb ({ aboutId, authorId }) { |
48 | var content = authorId === aboutId |
49 | ? 'self-identifies as' |
50 | : ['identifies ', idLink(aboutId), ' as'] |
51 | |
52 | return h('header', content) |
53 | } |
54 | |
55 | function profile ({ aboutId, name, image, description, api }) { |
56 | return h('div', [ |
57 | name |
58 | ? h('a', {href:'#'+aboutId}, name) |
59 | : null, |
60 | image |
61 | ? h('a', {href:'#'+aboutId}, h('img.avatar--fullsize', {src: api.blob_url(image)})) |
62 | : null, |
63 | description || null |
64 | ]) |
65 | } |
66 | |
67 | function idLink (id) { |
68 | if (!id) return null |
69 | |
70 | return h('a', {href:'#'+id}, id.slice(0,9) + '...') |
71 | } |
72 | |
73 | function asLink (ln) { |
74 | return typeof ln === 'string' ? ln : ln.link |
75 | } |
76 | |
77 |
Built with git-ssb-web