-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
23 lines (22 loc) · 677 Bytes
/
index.js
File metadata and controls
23 lines (22 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const htmlToText = require('html-to-text');
(function(){
const sanitize = function (post) {
const content = htmlToText.fromString(
post,
{
ignoreImage: true,
ignoreHref: true,
wordwrap: false,
uppercaseHeadings: false
}
);
return content;
}
hexo.extend.filter.register('after_post_render', function (data) {
const excerptLength = hexo.config.excerpt_length || 300;
const post = sanitize(data.content);
const excerpt = post.substr(0, excerptLength);
data.excerpt = excerpt;
return data;
});
})();