Files: c2cb876f7ef9db11df921ff5cebd31e0d8721cd1 / blog / html / post.js
1237 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(content => { |
26 | if (content.title) return content.title |
27 | if (content.text) return marksum.title(content.text) |
28 | }), |
29 | 'blog.html.summary': fromPost(content => { |
30 | if (content.summary) return content.summary |
31 | if (content.text) return marksum.summary(content.text) |
32 | }), |
33 | 'blog.html.thumbnail': function (data) { |
34 | const { type, thumbnail, text } = data.value.content |
35 | if('post' !== type) return |
36 | if (thumbnail) return thumbnail |
37 | |
38 | if (text) { |
39 | var img = marksum.image(text) |
40 | var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) |
41 | if(m) return m[1] |
42 | } |
43 | }, |
44 | 'blog.html.content': fromPost(content => content.text) |
45 | }) |
46 | } |
47 | |
48 | |
49 |
Built with git-ssb-web