2018-05-06 12:15:18 -04:00
|
|
|
/**
|
|
|
|
|
* 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 TRUNCATE_MARKER = /<!--\s*truncate\s*-->/;
|
|
|
|
|
|
|
|
|
|
function blogPostHasTruncateMarker(content) {
|
|
|
|
|
return TRUNCATE_MARKER.test(content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function extractBlogPostBeforeTruncate(content) {
|
|
|
|
|
return content.split(TRUNCATE_MARKER)[0];
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-28 00:09:50 -04:00
|
|
|
function removeExtension(pathStr) {
|
|
|
|
|
return pathStr.replace(/\.[^/.]+$/, '');
|
2018-07-04 14:13:30 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-28 00:09:50 -04:00
|
|
|
function getPath(pathStr, cleanUrl = false) {
|
|
|
|
|
if (!pathStr || !cleanUrl || !pathStr.endsWith('.html')) {
|
|
|
|
|
return pathStr;
|
2018-06-06 16:37:49 -04:00
|
|
|
}
|
2018-08-28 00:09:50 -04:00
|
|
|
return pathStr.endsWith('/index.html')
|
|
|
|
|
? pathStr.replace(/index\.html$/, '')
|
|
|
|
|
: removeExtension(pathStr);
|
2018-06-06 16:37:49 -04:00
|
|
|
}
|
|
|
|
|
|
2018-05-06 12:15:18 -04:00
|
|
|
module.exports = {
|
|
|
|
|
blogPostHasTruncateMarker,
|
|
|
|
|
extractBlogPostBeforeTruncate,
|
2018-06-06 16:37:49 -04:00
|
|
|
getPath,
|
2018-07-04 14:13:30 -04:00
|
|
|
removeExtension,
|
2018-05-06 12:15:18 -04:00
|
|
|
};
|