mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 10:52:35 +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
|
@ -28,39 +28,3 @@ And this.
|
|||
And this too.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`utils extractBlogPostSummary 1`] = `
|
||||
"---
|
||||
title: Truncation Example
|
||||
---
|
||||
|
||||
All this will be part of the blog post summary.
|
||||
|
||||
Even this.
|
||||
|
||||
<!--truncate-->
|
||||
|
||||
But anything from here on down will not be.
|
||||
|
||||
Not this.
|
||||
|
||||
Or this.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`utils extractBlogPostSummary 2`] = `
|
||||
"---
|
||||
title: Non-truncation Example
|
||||
---
|
||||
|
||||
All this will be part of the blog post summary.
|
||||
|
||||
Even this.
|
||||
|
||||
And anything from here on down will still be.
|
||||
|
||||
And this.
|
||||
|
||||
And this too.
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -38,15 +38,6 @@ describe('utils', () => {
|
|||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('extractBlogPostSummary', () => {
|
||||
expect(
|
||||
utils.extractBlogPostSummary(blogPostWithTruncateContents)
|
||||
).toMatchSnapshot();
|
||||
expect(
|
||||
utils.extractBlogPostSummary(blogPostWithoutTruncateContents)
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('getPath', () => {
|
||||
expect(utils.getPath('/docs/en/versioning.html', true)).toBe(
|
||||
'/docs/en/versioning'
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const BLOG_POST_SUMMARY_LENGTH = 250;
|
||||
const TRUNCATE_MARKER = /<!--\s*truncate\s*-->/;
|
||||
|
||||
function blogPostHasTruncateMarker(content) {
|
||||
|
@ -16,10 +15,6 @@ function extractBlogPostBeforeTruncate(content) {
|
|||
return content.split(TRUNCATE_MARKER)[0];
|
||||
}
|
||||
|
||||
function extractBlogPostSummary(content) {
|
||||
return content.substring(0, BLOG_POST_SUMMARY_LENGTH);
|
||||
}
|
||||
|
||||
function removeExtension(path) {
|
||||
return path.replace(/\.[^/.]+$/, '');
|
||||
}
|
||||
|
@ -36,7 +31,6 @@ function getPath(path, cleanUrl = false) {
|
|||
module.exports = {
|
||||
blogPostHasTruncateMarker,
|
||||
extractBlogPostBeforeTruncate,
|
||||
extractBlogPostSummary,
|
||||
getPath,
|
||||
removeExtension,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue