git ssb

2+

mixmix / ticktack



Tree: 1399cedf6a9c2dcf4b6662bdeb010225320af71c

Files: 1399cedf6a9c2dcf4b6662bdeb010225320af71c / message / html / subject.js

1176 bytesRaw
1const nest = require('depnest')
2const { h, when, send, resolve, Value, computed } = require('mutant')
3
4exports.gives = nest('message.html.subject')
5
6exports.needs = nest({
7 'message.html.markdown': 'first',
8})
9
10exports.create = function (api) {
11 return nest('message.html.subject', subject)
12
13 function subject (msg) {
14 const { subject, text } = msg.value.content
15 if(!(subject || text)) return
16 return api.message.html.markdown(firstLine(subject|| text))
17 }
18
19 // private
20
21 function firstLine (text) {
22 if(text.length < 80 && !~text.indexOf('\n')) return text
23
24 //get the first non-empty line
25 var line = text.trim().split('\n').shift().trim()
26
27 //always break on a space, so that links are preserved.
28 const leadingMentionsLength = countLeadingMentions(line)
29 const i = line.indexOf(' ', leadingMentionsLength + 80)
30 var sample = line.substring(0, ~i ? i : line.length)
31
32 const ellipsis = (sample.length < line.length) ? '...' : ''
33 return sample + ellipsis
34 }
35
36 function countLeadingMentions (str) {
37 return str.match(/^(\s*\[@[^\)]+\)\s*)*/)[0].length
38 // matches any number of pattern " [@...) " from start of line
39 }
40
41}
42

Built with git-ssb-web