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

27
lib/core/utils.js Normal file
View 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,
};