Files: 2b1e0cfa2f8ffcddd87d0ea71797a535a1352003 / blogs / blog.js
1398 bytesRaw
1 | var pull = require('pull-stream') |
2 | const h = require('mutant').h |
3 | |
4 | exports.gives = { |
5 | message: { |
6 | html: { |
7 | title: true, |
8 | summary: true, |
9 | thumbnail: true, |
10 | content: true |
11 | } |
12 | } |
13 | } |
14 | |
15 | exports.needs = { |
16 | message: { html: { markdown: 'first' } }, |
17 | sbot: { pull: { stream: 'first' } } |
18 | } |
19 | |
20 | |
21 | exports.create = function (api) { |
22 | |
23 | return { |
24 | message: { |
25 | html: { |
26 | title: function (data) { |
27 | if('blog' == typeof data.value.content.type) return |
28 | return data.value.content.title |
29 | }, |
30 | summary: function (data) { |
31 | if('blog' == typeof data.value.content.type) return |
32 | return data.value.content.title |
33 | }, |
34 | thumbnail: function (data) { |
35 | if('blog' == typeof data.value.content.type) return |
36 | return data.value.content.title |
37 | }, |
38 | content: function (data) { |
39 | if('blog' == typeof data.value.content.type) return |
40 | var div = h('Markdown') |
41 | pull( |
42 | api.sbot.pull.stream(function (sbot) { |
43 | return sbot.blobs.get(data.value.content.blog) |
44 | }), |
45 | pull.collect(function (err, ary) { |
46 | if(err) return |
47 | var md = api.message.html.markdown({text:Buffer.concat(ary).toString()}) |
48 | div.innerHTML = md.innerHTML |
49 | }) |
50 | ) |
51 | return div |
52 | } |
53 | } |
54 | } |
55 | } |
56 | } |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 |
Built with git-ssb-web