mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 19:27:48 +02:00
* fix: pretty url should only remove html extension * cleanUrl of '/index.html' should be '/'
36 lines
865 B
JavaScript
36 lines
865 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(pathStr) {
|
|
return pathStr.replace(/\.[^/.]+$/, '');
|
|
}
|
|
|
|
function getPath(pathStr, cleanUrl = false) {
|
|
if (!pathStr || !cleanUrl || !pathStr.endsWith('.html')) {
|
|
return pathStr;
|
|
}
|
|
return pathStr.endsWith('/index.html')
|
|
? pathStr.replace(/index\.html$/, '')
|
|
: removeExtension(pathStr);
|
|
}
|
|
|
|
module.exports = {
|
|
blogPostHasTruncateMarker,
|
|
extractBlogPostBeforeTruncate,
|
|
getPath,
|
|
removeExtension,
|
|
};
|