docusaurus/lib/core/utils.js
Laxman cfabaedc99 Fix: conflicting strings issue in translations (#917)
* 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
2018-08-29 00:04:02 +08:00

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,
};