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

Commit 97634d3

Browse files
Add super-short bio summary to mouseover popup.
This addresses #780 (Mouseover of profiles should include some of the user bio) in a relatively hap-hazard way.
1 parent 81f7b47 commit 97634d3

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

lib/depject/profile/html/preview.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ 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')
78

89
exports.needs = nest({
910
'about.obs.name': 'first',
11+
'about.obs.description': 'first',
1012
'about.html.image': 'first',
1113
'keys.sync.id': 'first',
1214
'sheet.display': 'first',
@@ -25,8 +27,10 @@ exports.create = function (api) {
2527
const plural = api.intl.sync.i18n_n
2628

2729
return nest('profile.html.preview', function (id) {
30+
const idLen = id.length
2831
const name = api.about.obs.name(id)
2932
const contact = api.profile.obs.contact(id)
33+
const description = api.about.obs.description(id)
3034

3135
return h('ProfilePreview', [
3236
h('header', [
@@ -42,7 +46,15 @@ exports.create = function (api) {
4246
]),
4347
h('section -publicKey', [
4448
h('pre', { title: i18n('Public key for this profile') }, id)
45-
])
49+
]),
50+
h(
51+
'section -profile', [
52+
computed(description, (description) => {
53+
const txt = removeMd(description)
54+
const summary = shortenDescription(txt, idLen)
55+
return summary
56+
})]
57+
)
4658
])
4759
]),
4860

@@ -95,6 +107,31 @@ exports.create = function (api) {
95107
])
96108
})
97109

110+
function shortenDescription (txt, len) {
111+
if (txt == null) {
112+
return ''
113+
}
114+
const line1 = txt.trim().split('\n', 1)[0]
115+
if (line1.length <= len) {
116+
return line1
117+
}
118+
const words = line1.split(' ')
119+
let result = words.shift()
120+
if (result.length > len) {
121+
return result.splice(0, len - 1) + ' …'
122+
}
123+
for (let i = 0; i < len; i++) {
124+
const currentWord = words.shift()
125+
// + 1 for the joining space, and +2 for the final ellipsis
126+
if (result.length + 1 + currentWord.length + 2 <= len) {
127+
result += ` ${currentWord}`
128+
} else {
129+
break
130+
}
131+
}
132+
return result + ' …'
133+
}
134+
98135
function displayMutualFriends (profiles) {
99136
api.sheet.profiles(profiles, i18n('Mutual Friends'))
100137
}

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

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

0 commit comments

Comments
 (0)