Skip to content

Commit dc42f07

Browse files
committed
Merge branches 'develop' and 'feature/NEXT-250' of https://team.human-connection.org/bitbucket/scm/hc/hc-api-feathers into feature/NEXT-250
# Conflicts: # server/hooks/create-excerpt.js
1 parent e82454b commit dc42f07

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

server/hooks/create-excerpt.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@
44
// const excerpt = require('html-excerpt');
55
const trunc = require('trunc-html');
66

7-
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
7+
module.exports = function (options = {
8+
field: 'content',
9+
length: 120
10+
}) { // eslint-disable-line no-unused-vars
811
return function (hook) {
9-
if(!hook.data || !hook.data.content) {
12+
console.log('TRY TO CREATE EXCERPT');
13+
console.log('field', options.field);
14+
if(!options.field || !hook.data[options.field]) return hook;
15+
16+
if(!hook.data || !hook.data[options.field]) {
1017
return hook;
1118
}
1219
/* eslint no-use-before-define: 0 */ // --> OFF
13-
const content = hook.data.content
20+
const text = hook.data[options.field]
1421
.replace(/\<br\>|\<\/br\>|\<\/ br\>|\<br\>|\<br\\\>|\<p\>|\<\/p\>/ig, "\n")
1522
.replace(/\<(strong|b|i|blockquote|pre|em|u|h[1-6])>|\<\/(strong|b|i|blockquote|pre|em|u|h[1-6])>/ig, '')
1623
.replace(/\<p\>\<br\>\<\/p\>/ig, ' ')
1724
.replace(/(\ )[2,]/ig, ' ')
1825
.trim();
19-
hook.data.contentExcerpt = trunc(content, 120, {
26+
hook.data[`${options.field}Excerpt`] = trunc(text, options.length, {
2027
ignoreTags: ['img', 'script']
2128
}).html;
2229

23-
hook.data.content = hook.data.content
30+
hook.data[options.field] = hook.data[options.field]
2431
.replace(/(\ )[2,]/ig, ' ')
2532
return Promise.resolve(hook);
2633
};

0 commit comments

Comments
 (0)