docusaurus/lib/core/utils.js
Endilie Yacop Sucipto defcbcc8ee Refactor + add more tests (Part 1) (#847)
* Refactor mdToHtml out

* Refactor routing + move it to server instead of core

* Refactor & Add more tests for server utils

* Refactor isSeparateCss function from server & generate

* Refactor insertTableOfContents from server & generate + add tests

* undo small nits
2018-07-13 11:31:37 -07:00

42 lines
973 B
JavaScript

/**
* 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);
}
function removeExtension(path) {
return path.replace(/\.[^/.]+$/, '');
}
function getPath(path, cleanUrl = false) {
if (cleanUrl) {
return path.endsWith('/index.html')
? path.replace(/\/index.html$/, '')
: removeExtension(path);
}
return path;
}
module.exports = {
blogPostHasTruncateMarker,
extractBlogPostBeforeTruncate,
extractBlogPostSummary,
getPath,
removeExtension,
};