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
27
lib/core/utils.js
Normal file
27
lib/core/utils.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* 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) {
|
||||
return TRUNCATE_MARKER.test(content);
|
||||
}
|
||||
|
||||
function extractBlogPostBeforeTruncate(content) {
|
||||
return content.split(TRUNCATE_MARKER)[0];
|
||||
}
|
||||
|
||||
function extractBlogPostSummary(content) {
|
||||
return content.substring(0, BLOG_POST_SUMMARY_LENGTH);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
blogPostHasTruncateMarker,
|
||||
extractBlogPostBeforeTruncate,
|
||||
extractBlogPostSummary,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue