git ssb

2+

mixmix / ticktack



Tree: ca44a0a40e4d24c2b6b42467fac6072170073817

Files: ca44a0a40e4d24c2b6b42467fac6072170073817 / blog / html / post.js

1234 bytesRaw
1var marksum = require('markdown-summary')
2var nest = require('depnest')
3
4exports.gives = nest({
5 'blog.html.title': true,
6 'blog.html.summary': true,
7 'blog.html.thumbnail': true,
8 'blog.html.content': true
9})
10
11exports.needs = nest({
12 'message.html.markdown': 'first'
13})
14
15exports.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