git ssb

2+

mixmix / ticktack



Tree: 7cf45e7c039b145503518e3560ac8943fa1e3708

Files: 7cf45e7c039b145503518e3560ac8943fa1e3708 / blogs / post.js

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

Built with git-ssb-web