mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-28 16:37:07 +02:00
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:
parent
609e1b42e7
commit
18158d6abc
7 changed files with 123 additions and 60 deletions
|
@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue