Skip to content

Commit 6a71d01

Browse files
committed
Merge remote-tracking branch 'origin/metascraper' into metascraper
2 parents 8b34fdd + 881bcc6 commit 6a71d01

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

server/hooks/create-excerpt.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* eslint-disable */
2-
32
// https://github.com/yangsibai/node-html-excerpt
43
// const excerpt = require('html-excerpt');
4+
5+
const sanitizeHtml = require('sanitize-html');
56
const trunc = require('trunc-html');
67

8+
const sanitizeOptions = {
9+
allowedTags: [ 'br' ]
10+
};
11+
712
module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
813
return function (hook) {
914

@@ -15,11 +20,10 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
1520

1621
try {
1722
/* eslint no-use-before-define: 0 */ // --> OFF
18-
const content = hook.data[options.field]
19-
.replace(/\<br\>|\<\/br\>|\<\/ br\>|\<br\>|\<br\\\>|\<p\>|\<\/p\>/ig, "\n")
20-
.replace(/\<(strong|b|i|blockquote|pre|em|u|h[1-6]|a)>|\<\/(strong|b|i|blockquote|pre|em|u|h[1-6]|a)>/ig, '')
23+
const content = sanitizeHtml(hook.data[options.field], sanitizeOptions)
24+
.replace(/\<br\>|\<\/br\>|\<\/ br\>|\<br\>|\<br\\\>/ig, "\n")
2125
.replace(/\<p\>\<br\>\<\/p\>/ig, ' ')
22-
.replace(/(\ )[2,]/ig, ' ')
26+
.replace(/(\ ){2,}/ig, ' ')
2327
.trim();
2428
hook.data[`${options.field}Excerpt`] = trunc(content, options.length, {
2529
ignoreTags: ['img', 'script', 'iframe']
@@ -32,7 +36,7 @@ module.exports = function (options = {}) { // eslint-disable-line no-unused-vars
3236
}
3337
}
3438
hook.data[options.field] = hook.data[options.field]
35-
.replace(/(\ )[2,]/ig, ' ')
39+
.replace(/(\ ){2,}/ig, ' ')
3640

3741
return Promise.resolve(hook);
3842
};

server/hooks/xss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function clean (dirty) {
1717
// Convert embeds to a-tags
1818
dirty = embedToAnchor(dirty);
1919
dirty = sanitizeHtml(dirty, {
20-
allowedTags: ['iframe', 'img', 'p', 'br', 'b', 'i', 'em', 'strong', 'a', 'pre', 'ul', 'li', 'ol', 'span'],
20+
allowedTags: ['iframe', 'img', 'p', 'br', 'b', 'i', 'em', 'strong', 'a', 'pre', 'ul', 'li', 'ol', 'span', 'blockquote'],
2121
allowedAttributes: {
2222
a: ['href', 'class', 'target', 'data-*'],
2323
img: [ 'src' ],

0 commit comments

Comments
 (0)