mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 10:17:55 +02:00
* fix: truncate blogpost properly with truncate-html * revert test file change * chore: truncate blogpost for feed changelog
36 lines
806 B
JavaScript
36 lines
806 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 TRUNCATE_MARKER = /<!--\s*truncate\s*-->/;
|
|
|
|
function blogPostHasTruncateMarker(content) {
|
|
return TRUNCATE_MARKER.test(content);
|
|
}
|
|
|
|
function extractBlogPostBeforeTruncate(content) {
|
|
return content.split(TRUNCATE_MARKER)[0];
|
|
}
|
|
|
|
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,
|
|
getPath,
|
|
removeExtension,
|
|
};
|