mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 03:08:17 +02:00
* Fix conflicting strings issue in translations * Preserve structure of `customTranslations` * Use `deepmerge` to merge whole of `localized-strings` * Simplify and make deep property access on an object safe * Fix deep property accessor and rename it to idx
41 lines
965 B
JavaScript
41 lines
965 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);
|
|
}
|
|
|
|
function idx(target, path) {
|
|
return path.reduce((obj, key) => obj && obj[key], target);
|
|
}
|
|
|
|
module.exports = {
|
|
blogPostHasTruncateMarker,
|
|
extractBlogPostBeforeTruncate,
|
|
getPath,
|
|
removeExtension,
|
|
idx,
|
|
};
|