mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-25 14:07:50 +02:00
Move Docusaurus 1 files into directory (#966)
* Move Docusaurus 1 into v1 directory * Update Circle CI commands for new v1 dir * Remove OC * Fix tests
This commit is contained in:
parent
9d4a5d5359
commit
f2927a9fc4
291 changed files with 7591 additions and 6532 deletions
59
v1/lib/core/utils.js
Normal file
59
v1/lib/core/utils.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* 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 spawn = require('cross-spawn');
|
||||
|
||||
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, keyPaths) {
|
||||
return (
|
||||
target &&
|
||||
(Array.isArray(keyPaths)
|
||||
? keyPaths.reduce((obj, key) => obj && obj[key], target)
|
||||
: target[keyPaths])
|
||||
);
|
||||
}
|
||||
|
||||
function getGitLastUpdated(filepath) {
|
||||
const timeSpan = spawn
|
||||
.sync('git', ['log', '-1', '--format=%ct', filepath])
|
||||
.stdout.toString('utf-8');
|
||||
if (timeSpan) {
|
||||
const date = new Date(parseInt(timeSpan, 10) * 1000);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
blogPostHasTruncateMarker,
|
||||
extractBlogPostBeforeTruncate,
|
||||
getGitLastUpdated,
|
||||
getPath,
|
||||
removeExtension,
|
||||
idx,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue