git ssb

10+

Matt McKegg / patchwork



Tree: b6089670d854fcefa6bc5ca05636a801707deb30

Files: b6089670d854fcefa6bc5ca05636a801707deb30 / modules / message-name.js

1003 bytesRaw
1
2var sbot_get = require('patchbay/plugs').first(exports.sbot_get = [])
3
4exports.message_name = function (id, cb) {
5 sbot_get(id, function (err, value) {
6 if (err && err.name === 'NotFoundError') {
7 return cb(null, id.substring(0, 10) + '...(missing)')
8 } else if (value.content.type === 'post' && typeof value.content.text === 'string') {
9 if (value.content.text.trim()) {
10 return cb(null, titleFromMarkdown(value.content.text, 40))
11 }
12 } else if (typeof value.content.text === 'string') {
13 return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30))
14 }
15
16 return cb(null, id.substring(0, 10) + '...')
17 })
18}
19
20function titleFromMarkdown (text, max) {
21 text = text.trim().split('\n', 2).join('\n')
22 text = text.replace(/_|`|\*|\#|\[.*?\]|\(\S*?\)/g, '').trim()
23 text = text.replace(/\:$/, '')
24 text = text.trim().split('\n', 1)[0].trim()
25 if (text.length > max) {
26 text = text.substring(0, max - 2) + '...'
27 }
28 return text
29}
30

Built with git-ssb-web