fix: truncate blogpost properly with truncate-html (#880)

* fix: truncate blogpost properly with truncate-html

* revert test file change

* chore: truncate blogpost for feed changelog
This commit is contained in:
Endilie Yacop Sucipto 2018-08-02 15:16:26 +08:00 committed by GitHub
parent 609e1b42e7
commit 18158d6abc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 123 additions and 60 deletions

View file

@ -6,6 +6,9 @@
*/
const Feed = require('feed');
const truncateHtml = require('truncate-html');
const BLOG_POST_SUMMARY_LENGTH = 250;
const CWD = process.cwd();
const siteConfig = require(`${CWD}/siteConfig.js`);
@ -40,9 +43,10 @@ module.exports = function(type) {
MetadataBlog.forEach(post => {
const url = `${blogRootURL}/${post.path}`;
const content = utils.blogPostHasTruncateMarker(post.content)
? utils.extractBlogPostBeforeTruncate(post.content)
: utils.extractBlogPostSummary(post.content.trim());
const description = utils.blogPostHasTruncateMarker(post.content)
? renderMarkdown(utils.extractBlogPostBeforeTruncate(post.content))
: truncateHtml(renderMarkdown(post.content), BLOG_POST_SUMMARY_LENGTH);
feed.addItem({
title: post.title,
link: url,
@ -53,7 +57,7 @@ module.exports = function(type) {
},
],
date: new Date(post.date),
description: renderMarkdown(content),
description,
});
});