mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-20 10:08:17 +02:00
feat: add loadEnv to check if translation / versioning is enabled
This commit is contained in:
parent
828d99dc8e
commit
1ff6733464
15 changed files with 608 additions and 20 deletions
37
lib/load/docs/index.js
Normal file
37
lib/load/docs/index.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const fm = require('front-matter');
|
||||
const globby = require('globby');
|
||||
const {encodePath, fileToPath} = require('../utils');
|
||||
|
||||
function parse(fileString) {
|
||||
if (!fm.test(fileString)) {
|
||||
return {metadata: null, content: fileString};
|
||||
}
|
||||
const {attributes: metadata, body: content} = fm(fileString);
|
||||
|
||||
return {metadata, content};
|
||||
}
|
||||
|
||||
async function loadDocs(docsDir) {
|
||||
const docsFiles = await globby(['**/*.md'], {
|
||||
cwd: docsDir
|
||||
});
|
||||
|
||||
const docsData = await Promise.all(
|
||||
docsFiles.map(async source => {
|
||||
const filepath = path.resolve(docsDir, source);
|
||||
const fileString = await fs.readFile(filepath, 'utf-8');
|
||||
const {metadata} = parse(fileString);
|
||||
|
||||
return {
|
||||
path: encodePath(fileToPath(source)),
|
||||
source,
|
||||
...metadata
|
||||
};
|
||||
})
|
||||
);
|
||||
return docsData;
|
||||
}
|
||||
|
||||
module.exports = loadDocs;
|
Loading…
Add table
Add a link
Reference in a new issue