@@ -4,9 +4,11 @@ const map = require('mutant/map')
44const when = require ( 'mutant/when' )
55const computed = require ( 'mutant/computed' )
66const send = require ( 'mutant/send' )
7+ const removeMd = require ( 'remove-markdown' )
78
89exports . 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 }
0 commit comments