mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 14:06:59 +02:00
chore: prepare for docs sidebar
This commit is contained in:
parent
2141e6ea90
commit
b477863a30
9 changed files with 350 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
|||
const path = require('path');
|
||||
const fm = require('front-matter');
|
||||
const escapeStringRegexp = require('escape-string-regexp');
|
||||
const fs = require('fs-extra');
|
||||
|
||||
const genPath = path.resolve(__dirname, '../core/generated');
|
||||
|
@ -40,9 +42,40 @@ function fileToComponentName(file) {
|
|||
return ext ? ext.toUpperCase() + str : str;
|
||||
}
|
||||
|
||||
function idx(target, keyPaths) {
|
||||
return (
|
||||
target &&
|
||||
(Array.isArray(keyPaths)
|
||||
? keyPaths.reduce((obj, key) => obj && obj[key], target)
|
||||
: target[keyPaths])
|
||||
);
|
||||
}
|
||||
|
||||
function getSubFolder(file, refDir) {
|
||||
const separator = escapeStringRegexp(path.sep);
|
||||
const baseDir = escapeStringRegexp(path.basename(refDir));
|
||||
const regexSubFolder = new RegExp(
|
||||
`${baseDir}${separator}(.*?)${separator}.*`
|
||||
);
|
||||
const match = regexSubFolder.exec(file);
|
||||
return match && match[1];
|
||||
}
|
||||
|
||||
function parse(fileString) {
|
||||
if (!fm.test(fileString)) {
|
||||
return {metadata: null, content: fileString};
|
||||
}
|
||||
const {attributes: metadata, body: content} = fm(fileString);
|
||||
|
||||
return {metadata, content};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
encodePath,
|
||||
generate,
|
||||
fileToPath,
|
||||
fileToComponentName
|
||||
fileToComponentName,
|
||||
getSubFolder,
|
||||
idx,
|
||||
parse
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue