Files: 2cf06eb4b4d0e4ac4b6f5dced90ef5da82a0a8fd / blog / html / post.js
1234 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 | function fromPost (fn) { |
17 | return function (data) { |
18 | if (data.value.content.type !== 'post') return |
19 | return api.message.html.markdown({text: fn(data.value.content)}) |
20 | } |
21 | } |
22 | |
23 | return nest({ |
24 | 'blog.html.title': fromPost(content => { |
25 | if (content.title) return content.title |
26 | if (content.text) return marksum.title(content.text) |
27 | }), |
28 | 'blog.html.summary': fromPost(content => { |
29 | if (content.summary) return content.summary |
30 | if (content.text) return marksum.summary(content.text) |
31 | }), |
32 | 'blog.html.thumbnail': function (data) { |
33 | const { type, thumbnail, text } = data.value.content |
34 | if (type !== 'post') return |
35 | if (thumbnail) return thumbnail |
36 | |
37 | if (text) { |
38 | var img = marksum.image(text) |
39 | var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) |
40 | if (m) return m[1] |
41 | } |
42 | }, |
43 | 'blog.html.content': fromPost(content => content.text) |
44 | }) |
45 | } |
46 |
Built with git-ssb-web