mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 23:27:28 +02:00
Extract blog post truncation logic and add tests (#640)
This commit is contained in:
parent
5b3f54741e
commit
8d676e6a5a
13 changed files with 192 additions and 30 deletions
|
@ -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),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue