Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 8df4f45

Browse files
Remove remove-markdown dependency.
We already had a method to make a short version of a markdown text. It was stuck deep in a depject module, so I ripped it out of there and put it into its own module. It is now require()d in the depject module and in the new bio preview code.
1 parent 97634d3 commit 8df4f45

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

lib/depject/message/async/name.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const nest = require('depnest')
22
const ref = require('ssb-ref')
3+
const { titleFromMarkdown, truncate } = require('../../../markdownSummary')
34
const { resolve, onceTrue } = require('mutant')
45

56
exports.needs = nest({
@@ -28,10 +29,10 @@ exports.create = function (api) {
2829
return cb(null, truncate(value.content.title, 40))
2930
} else if (value && value.content.type === 'post' && typeof value.content.text === 'string') {
3031
if (value.content.text.trim()) {
31-
return cb(null, titleFromMarkdown(value.content.text, 40) || fallbackName)
32+
return cb(null, titleFromMarkdown(value.content.text, 40, 3) || fallbackName)
3233
}
3334
} else if (value && typeof value.content.text === 'string') {
34-
return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30))
35+
return cb(null, value.content.type + ': ' + titleFromMarkdown(value.content.text, 30, 3))
3536
} else {
3637
return getAboutName(id, cb)
3738
}
@@ -49,19 +50,3 @@ exports.create = function (api) {
4950
})
5051
}
5152
}
52-
53-
function titleFromMarkdown (text, max) {
54-
text = text.trim().split('\n', 3).join('\n')
55-
text = text.replace(/_|`|\*|#|^\[@.*?]|\[|]|\(\S*?\)/g, '').trim()
56-
text = text.replace(/:$/, '')
57-
text = text.trim().split('\n', 1)[0].trim()
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) + '...'
65-
}
66-
return text
67-
}

lib/depject/profile/html/preview.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const map = require('mutant/map')
44
const when = require('mutant/when')
55
const computed = require('mutant/computed')
66
const send = require('mutant/send')
7-
const removeMd = require('remove-markdown')
7+
const { titleFromMarkdown } = require('../../../markdownSummary')
88

99
exports.needs = nest({
1010
'about.obs.name': 'first',
@@ -50,8 +50,9 @@ exports.create = function (api) {
5050
h(
5151
'section -profile', [
5252
computed(description, (description) => {
53-
const txt = removeMd(description)
54-
const summary = shortenDescription(txt, idLen)
53+
// const txt = removeMd(description)
54+
// const summary = shortenDescription(txt, idLen)
55+
const summary = titleFromMarkdown(description, idLen, 1)
5556
return summary
5657
})]
5758
)

lib/markdownSummary.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
exports.titleFromMarkdown = (text, max, maxLines) => {
3+
if (text === null) {
4+
return ''
5+
}
6+
text = text.trim().split('\n', maxLines + 1).join('\n')
7+
text = text.replace(/_|`|\*|#|^\[@.*?]|\[|]|\(\S*?\)/g, '').trim()
8+
text = text.replace(/:$/, '')
9+
text = text.trim().split('\n', 1)[0].trim()
10+
text = module.exports.truncate(text, max)
11+
return text
12+
}
13+
14+
exports.truncate = (text, maxLength) => {
15+
if (text.length > maxLength) {
16+
text = text.substring(0, maxLength - 2) + '...'
17+
}
18+
return text
19+
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"pull-pushable": "^2.2.0",
5959
"pull-reconnect": "0.0.3",
6060
"pull-stream": "^3.6.14",
61-
"remove-markdown": "^0.3.0",
6261
"require-style": "^1.1.0",
6362
"run-parallel": "^1.1.9",
6463
"scuttle-blog": "^1.0.1",

0 commit comments

Comments
 (0)