git ssb

2+

mixmix / ticktack



Tree: 35ee32eefff5c36f236876e4918c46cbeb22ef6d

Files: 35ee32eefff5c36f236876e4918c46cbeb22ef6d / blog / html / post.js

1174 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
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 var img = marksum.image(content.text)
36 var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img)
37 if(m) return m[1]
38 },
39 'blog.html.content': fromPost(function (content) {
40 return content.text
41 })
42 })
43}
44
45
46

Built with git-ssb-web