Extract blog post truncation logic and add tests (#640)

This commit is contained in:
Yangshun Tay 2018-05-06 09:15:18 -07:00 committed by GitHub
parent 5b3f54741e
commit 8d676e6a5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 192 additions and 30 deletions

View file

@ -19,6 +19,7 @@ const blogFolder = path.resolve('../blog/');
const blogRootURL = siteConfig.url + siteConfig.baseUrl + 'blog';
const siteImageURL =
siteConfig.url + siteConfig.baseUrl + siteConfig.headerIcon;
const utils = require('../core/utils');
const renderMarkdown = require('../core/renderMarkdown.js');
@ -56,18 +57,9 @@ module.exports = function(type) {
MetadataBlog.forEach(post => {
const url = blogRootURL + '/' + post.path;
let content = '';
if (post.content.indexOf('<!--truncate-->') == -1) {
content = post.content.trim().substring(0, 250);
} else {
let contentArr = post.content.split('<!--truncate-->');
if (contentArr.length > 0) {
content = contentArr[0];
}
}
content = renderMarkdown(content);
const content = utils.blogPostHasTruncateMarker(post.content)
? utils.extractBlogPostBeforeTruncate(post.content)
: utils.extractBlogPostSummary(post.content.trim());
feed.addItem({
title: post.title,
link: url,
@ -78,7 +70,7 @@ module.exports = function(type) {
},
],
date: new Date(post.date),
description: content,
description: renderMarkdown(content),
});
});