Files: f1d5a7c472bb8e838a7fd395f59be8d473f8a872 / blogs / post.js
1550 bytesRaw
1 | var marksum = require('markdown-summary') |
2 | |
3 | //var markdown = require('ssb-markdown') |
4 | |
5 | |
6 | exports.gives = { |
7 | message: { |
8 | html: { |
9 | title: true, |
10 | summary: true, |
11 | thumbnail: true, |
12 | content: true |
13 | } |
14 | } |
15 | } |
16 | |
17 | exports.needs = { |
18 | message: { html: { markdown: 'first' } } |
19 | } |
20 | |
21 | |
22 | exports.create = function (api) { |
23 | |
24 | function render (source) { |
25 | return markdown.block(source, { |
26 | emoji: (emoji) => { |
27 | return renderEmoji(emoji, api.emoji.sync.url(emoji)) |
28 | }, |
29 | toUrl: (id) => { |
30 | if (ref.isBlob(id)) return api.blob.sync.url(id) |
31 | return id |
32 | }, |
33 | imageLink: (id) => id |
34 | }) |
35 | } |
36 | function fromPost(fn) { |
37 | return function (data) { |
38 | if('post' !== data.value.content.type) return |
39 | return api.message.html.markdown ({text: fn(data.value.content)}) |
40 | } |
41 | } |
42 | |
43 | return { |
44 | message: { |
45 | html: { |
46 | title: fromPost(function (content) { |
47 | return content.title || marksum.title(content.text) |
48 | }), |
49 | summary: fromPost(function (content) { |
50 | return content.summary || marksum.summary(content.text) |
51 | }), |
52 | thumbnail: function (data) { |
53 | if('post' !== data.value.content.type) return |
54 | var content = data.value.content |
55 | if(content.thumbnail) return content.thumbnail |
56 | var img = marksum.image(content.text) |
57 | var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) |
58 | if(m) return m[1] |
59 | }, |
60 | content: fromPost(function (content) { |
61 | return content.text |
62 | }) |
63 | } |
64 | } |
65 | } |
66 | } |
67 | |
68 | |
69 | |
70 |
Built with git-ssb-web