Files: 822d7aba3e5e907a98c48a9abe3223cc278c6c95 / modules_basic / about.js
2423 bytesRaw
1 | var fs = require('fs') |
2 | var Path = require('path') |
3 | var h = require('../h') |
4 | var when = require('@mmckegg/mutant/when') |
5 | |
6 | exports.needs = { |
7 | blob_url: 'first', |
8 | markdown: 'first' |
9 | } |
10 | |
11 | exports.gives = { |
12 | mcss: true, |
13 | message_content: true, |
14 | message_content_mini: true |
15 | } |
16 | |
17 | exports.create = function (api) { |
18 | return { |
19 | message_content, |
20 | message_content_mini, |
21 | mcss: () => fs.readFileSync(Path.join(__dirname, 'about.mcss'), 'utf8') |
22 | } |
23 | |
24 | function message_content (msg) { |
25 | if (msg.value.content.type !== 'about') return |
26 | |
27 | var { content: about, author: authorId } = msg.value |
28 | var { about: aboutId, name, image, description } = about |
29 | |
30 | if (!aboutId) return null |
31 | |
32 | return h('About', [ |
33 | Name({ aboutId, authorId, name }), |
34 | Image({ aboutId, authorId, image }), |
35 | Description({ aboutId, authorId, description }) |
36 | ]) |
37 | } |
38 | |
39 | function message_content_mini (msg) { |
40 | if (msg.value.content.type !== 'about') return |
41 | |
42 | var { content: about, author: authorId } = msg.value |
43 | var { about: aboutId, name, image, description } = about |
44 | |
45 | if (!aboutId) return null |
46 | if (image || description) return null |
47 | |
48 | return h('About', Name({ aboutId, authorId, name })) |
49 | } |
50 | |
51 | |
52 | function Name ({ aboutId, authorId, name }) { |
53 | if (!name) return null |
54 | return h('section -name', [ |
55 | h('header', when(authorId === aboutId, |
56 | 'self-identifies as', |
57 | ['identifies ', targetLink(aboutId), ' as'] |
58 | )), |
59 | h('section', h( |
60 | 'a -name', |
61 | { href: `#${aboutId}` }, |
62 | name |
63 | )) |
64 | ]) |
65 | } |
66 | |
67 | function Image ({ aboutId, authorId, image }) { |
68 | if (!image) return null |
69 | return h('section -image', [ |
70 | h('header', when(authorId === aboutId, |
71 | 'self-portrays as', |
72 | ['portrays ', targetLink(aboutId), ' as'] |
73 | )), |
74 | h('section', h( |
75 | 'a -image', |
76 | { href: `#${aboutId}` }, |
77 | h('img', { src: api.blob_url(image) }) |
78 | )) |
79 | ]) |
80 | } |
81 | |
82 | function Description ({ aboutId, authorId, description }) { |
83 | if (!description) return null |
84 | return h('section -description', [ |
85 | h('header', when(authorId === aboutId, |
86 | 'self-describes as', |
87 | ['describes ', targetLink(aboutId), ' as'] |
88 | )), |
89 | h('section', api.markdown(description)) |
90 | ]) |
91 | } |
92 | } |
93 | |
94 | function targetLink (aboutId) { |
95 | const content = aboutId.slice(0, 9) + '...' |
96 | return h( |
97 | 'a -target', |
98 | { href: `#${aboutId}` }, |
99 | content |
100 | ) |
101 | } |
102 |
Built with git-ssb-web