Skip to content

Commit 1b36d49

Browse files
fixed excerpt and moderator hooks
1 parent b063a32 commit 1b36d49

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

server/hooks/create-excerpt.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
2121
try {
2222
/* eslint no-use-before-define: 0 */ // --> OFF
2323
const content = sanitizeHtml(hook.data[options.field], sanitizeOptions)
24-
.replace(/\<br\>|\<\/br\>|\<\/ br\>|\<br\>|\<br\\\>/ig, "\n")
25-
.replace(/\<p\>\<br\>\<\/p\>/ig, ' ')
24+
.replace(/\<br\s*\>|\<br\s*\/\>/ig, "\n")
2625
.replace(/(\ ){2,}/ig, ' ')
2726
.trim();
2827
hook.data[`${options.field}Excerpt`] = trunc(content, options.length, {
2928
ignoreTags: ['img', 'script', 'iframe']
3029
}).html;
3130
} catch (err) {
32-
if (hook.data.teaserImg) {
33-
hook.data[`${options.field}Excerpt`] = '-----';
34-
} else {
35-
throw new Error('Text content needed!');
36-
}
31+
throw new Error('Text content needed!');
3732
}
3833
hook.data[options.field] = hook.data[options.field]
3934
.replace(/(\ ){2,}/ig, ' ')

server/hooks/is-moderator-boolean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Check if user is moderator
22
module.exports = () => hook => {
3-
if(!hook.params || !hook.params.user || !['admin','moderator'].includes(hook.params.user.role)) {
3+
if(!hook.params || !hook.params.user) {
44
return false;
55
}
6-
return true;
6+
return ['admin', 'moderator'].includes(hook.params.user.role);
77
};

server/services/organizations/organizations.hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = {
4343
),
4444
associateCurrentUser(),
4545
createSlug({ field: 'name' }),
46-
createExcerpt({ field: 'description '}),
46+
createExcerpt({ field: 'description' }),
4747
saveRemoteImages(['logo', 'coverImg'])
4848
],
4949
update: [
@@ -56,7 +56,7 @@ module.exports = {
5656
restrictToOwner()
5757
),
5858
createSlug({ field: 'name', overwrite: true }),
59-
createExcerpt({ field: 'description '}),
59+
createExcerpt({ field: 'description' }),
6060
saveRemoteImages(['logo', 'coverImg'])
6161
],
6262
patch: [

0 commit comments

Comments
 (0)