@@ -8,7 +8,11 @@ const { getByDot, setByDot } = require('feathers-hooks-common');
8
8
const { isEmpty } = require ( 'lodash' ) ;
9
9
10
10
const sanitizeOptions = {
11
- allowedTags : [ 'br' , 'a' , 'p' ]
11
+ allowedTags : [ 'p' , 'br' , 'a' , 'span' , 'blockquote' ] ,
12
+ allowedAttributes : {
13
+ a : [ 'href' , 'class' , 'target' , 'data-*' , 'contenteditable' ] ,
14
+ span : [ 'contenteditable' , 'class' , 'data-*' ]
15
+ } ,
12
16
} ;
13
17
14
18
module . exports = function ( options = { } ) { // eslint-disable-line no-unused-vars
@@ -29,14 +33,19 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
29
33
. replace ( / ( \ ) { 2 , } / ig, ' ' )
30
34
. trim ( ) ;
31
35
32
- contentSanitized = trunc ( contentSanitized , options . length ) . html ;
36
+ contentBefore = trunc ( content , 9999999999 ) ;
37
+ const contentTruncated = trunc ( contentSanitized , options . length ) ;
38
+ hook . app . debug ( 'contentBefore' ) ;
39
+ hook . app . debug ( contentBefore . text . length ) ;
40
+ hook . app . debug ( 'contentTruncated' ) ;
41
+ hook . app . debug ( contentTruncated . text . length ) ;
33
42
34
- setByDot ( hook . data , 'hasMore' , contentSanitized . length < content . length ) ;
43
+ const hasMore = contentBefore . text . length > ( contentTruncated . text . length + 20 ) ;
44
+ setByDot ( hook . data , 'hasMore' , hasMore ) ;
35
45
36
46
// set excerpt
37
- setByDot ( hook . data , `${ options . field } Excerpt` , contentSanitized )
47
+ setByDot ( hook . data , `${ options . field } Excerpt` , hasMore ? contentTruncated . html : content . replace ( / ( \ ) { 2 , } / ig , ' ' ) )
38
48
} catch ( err ) {
39
- hook . app . error ( err ) ;
40
49
throw new Error ( err ) ;
41
50
}
42
51
// trim content
0 commit comments