mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
[WIP] Allow custom subpath for docs within the "docs" folder
e.g., The default is `docs/*.md` This allows `docs/somedir/*.md` or `docs/somedir/anotherdir/*.md` Notes: - All URLs are still /docs/*.html (i.e. the subpath does not get preserved in the link). - Files in `translated_docs`, if any, will still only be one level - This should not affect translations or versioning
This commit is contained in:
parent
9f32a28d32
commit
dc0c1390c4
5 changed files with 24 additions and 12 deletions
|
@ -16,6 +16,8 @@ const versionFallback = require("./versionFallback.js");
|
|||
|
||||
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
|
||||
|
||||
|
||||
|
||||
let languages;
|
||||
if (fs.existsSync(CWD + "/languages.js")) {
|
||||
languages = require(CWD + "/languages.js");
|
||||
|
@ -29,6 +31,15 @@ if (fs.existsSync(CWD + "/languages.js")) {
|
|||
];
|
||||
}
|
||||
|
||||
// Can add additional path information to the docs folder
|
||||
// e.g., docs/whereDocsReallyExist
|
||||
// All .md docs still (currently) must be in one flat directory hierarchy.
|
||||
// e.g., docs/whereDocsReallyExist/*.md (all .md files in this dir)
|
||||
function getDocsPath() {
|
||||
return siteConfig.docsAdditionalPath
|
||||
? "docs" + siteConfig.docsAdditionalPath
|
||||
: "docs";
|
||||
}
|
||||
// returns map from id to object containing sidebar ordering info
|
||||
function readSidebar() {
|
||||
let allSidebars;
|
||||
|
@ -114,7 +125,7 @@ function extractMetadata(content) {
|
|||
function processMetadata(file) {
|
||||
const result = extractMetadata(fs.readFileSync(file, "utf8"));
|
||||
|
||||
const regexSubFolder = /docs\/(.*)\/.*/;
|
||||
let regexSubFolder = new RegExp("/" + getDocsPath() + "\/(.*)\/.*/");
|
||||
|
||||
let language = "en";
|
||||
const match = regexSubFolder.exec(file);
|
||||
|
@ -190,7 +201,7 @@ function generateMetadataDocs() {
|
|||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
const regexSubFolder = /translated_docs\/(.*)\/.*/;
|
||||
|
||||
const enabledLanguages = [];
|
||||
|
@ -202,7 +213,7 @@ function generateMetadataDocs() {
|
|||
const defaultMetadatas = {};
|
||||
|
||||
// metadata for english files
|
||||
let files = glob.sync(CWD + "/../docs/**");
|
||||
let files = glob.sync(CWD + "/../" + getDocsPath() + "/**");
|
||||
files.forEach(file => {
|
||||
let language = "en";
|
||||
|
||||
|
@ -210,7 +221,7 @@ function generateMetadataDocs() {
|
|||
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
const res = processMetadata(file);
|
||||
|
||||
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
|
@ -389,6 +400,7 @@ function generateMetadataBlog() {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
getDocsPath,
|
||||
readSidebar,
|
||||
extractMetadata,
|
||||
processMetadata,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue