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