Files: b02d5837685a7fb8e42751b875db010b8ec801c6 / blog / html / post.js
1175 bytesRaw
1 | var marksum = require('markdown-summary') |
2 | var nest = require('depnest') |
3 | |
4 | exports.gives = nest({ |
5 | 'blog.html.title': true, |
6 | 'blog.html.summary': true, |
7 | 'blog.html.thumbnail': true, |
8 | 'blog.html.content': true, |
9 | }) |
10 | |
11 | exports.needs = nest({ |
12 | 'message.html.markdown': 'first', |
13 | }) |
14 | |
15 | exports.create = function (api) { |
16 | |
17 | function fromPost(fn) { |
18 | return function (data) { |
19 | if('post' !== data.value.content.type) return |
20 | return api.message.html.markdown ({text: fn(data.value.content)}) |
21 | } |
22 | } |
23 | |
24 | return nest({ |
25 | 'blog.html.title': fromPost(function (content) { |
26 | return content.title || marksum.title(content.text) |
27 | }), |
28 | 'blog.html.summary': fromPost(function (content) { |
29 | return content.summary || marksum.summary(content.text) |
30 | }), |
31 | 'blog.html.thumbnail': function (data) { |
32 | if('post' !== data.value.content.type) return |
33 | var content = data.value.content |
34 | if(content.thumbnail) return content.thumbnail |
35 | |
36 | var img = marksum.image(content.text) |
37 | var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) |
38 | if(m) return m[1] |
39 | }, |
40 | 'blog.html.content': fromPost(function (content) { |
41 | return content.text |
42 | }) |
43 | }) |
44 | } |
45 | |
46 | |
47 |
Built with git-ssb-web