Commit 9b421343eb76d9c775a0f125bdc96770f966c4ea
message.async.name: handle blog titles
Matt McKegg committed on 4/10/2018, 9:16:21 AMParent: 4ce4ef5db3d9c2b861e196de6bbf9f82064c8064
Files changed
message/async/name.js | changed |
message/async/name.js | ||
---|---|---|
@@ -27,8 +27,10 @@ | ||
27 | 27 … | } else if (value && value.content.type === 'post' && typeof value.content.text === 'string') { |
28 | 28 … | if (value.content.text.trim()) { |
29 | 29 … | return cb(null, titleFromMarkdown(value.content.text, 40) || fallbackName) |
30 | 30 … | } |
31 … | + } else if (value && typeof value.content.title === 'string') { | |
32 … | + return cb(null, truncate(value.content.title, 40)) | |
31 | 33 … | } else if (value && typeof value.content.text === 'string') { |
32 | 34 … | return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30)) |
33 | 35 … | } else { |
34 | 36 … | return getAboutName(id, cb) |
@@ -52,9 +54,14 @@ | ||
52 | 54 … | text = text.trim().split('\n', 3).join('\n') |
53 | 55 … | text = text.replace(/_|`|\*|#|^\[@.*?]|\[|]|\(\S*?\)/g, '').trim() |
54 | 56 … | text = text.replace(/:$/, '') |
55 | 57 … | text = text.trim().split('\n', 1)[0].trim() |
56 | - if (text.length > max) { | |
57 | - text = text.substring(0, max - 2) + '...' | |
58 … | + text = truncate(text, max) | |
59 … | + return text | |
60 … | +} | |
61 … | + | |
62 … | +function truncate (text, maxLength) { | |
63 … | + if (text.length > maxLength) { | |
64 … | + text = text.substring(0, maxLength - 2) + '...' | |
58 | 65 … | } |
59 | 66 … | return text |
60 | 67 … | } |
Built with git-ssb-web