mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +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
|
@ -129,7 +129,7 @@ function execute() {
|
|||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = CWD + "/../docs/" + metadata.source;
|
||||
file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
|
||||
} else {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
|
@ -219,9 +219,9 @@ function execute() {
|
|||
});
|
||||
|
||||
// copy docs assets if they exist
|
||||
if (fs.existsSync(CWD + "/../docs/assets")) {
|
||||
if (fs.existsSync(CWD + "/../" + readMetadata.getDocsPath() + "/assets")) {
|
||||
fs.copySync(
|
||||
CWD + "/../docs/assets",
|
||||
CWD + "/../" + readMetadata.getDocsPath() + "/assets",
|
||||
CWD + "/build/" + siteConfig.projectName + "/docs/assets"
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -177,7 +177,7 @@ function execute(port) {
|
|||
}
|
||||
} else {
|
||||
if (metadata.language === "en") {
|
||||
file = CWD + "/../docs/" + metadata.source;
|
||||
file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
|
||||
} else {
|
||||
file =
|
||||
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
|
||||
|
@ -485,7 +485,7 @@ function execute(port) {
|
|||
// serve static assets from these locations
|
||||
app.use(
|
||||
siteConfig.baseUrl + "docs/assets/",
|
||||
express.static(CWD + "/../docs/assets")
|
||||
express.static(CWD + "/../" + readMetadata.getDocsPath() + "/assets")
|
||||
);
|
||||
app.use(
|
||||
siteConfig.baseUrl + "blog/assets/",
|
||||
|
|
|
@ -65,7 +65,7 @@ const versionFolder = CWD + "/versioned_docs/version-" + version;
|
|||
mkdirp.sync(versionFolder);
|
||||
|
||||
// copy necessary files to new version, changing some of its metadata to reflect the versioning
|
||||
let files = glob.sync(CWD + "/../docs/*");
|
||||
let files = glob.sync(CWD + "/../" + readMetadata.getDocsPath() + "/*");
|
||||
files.forEach(file => {
|
||||
const ext = path.extname(file);
|
||||
if (ext !== ".md" && ext !== ".markdown") {
|
||||
|
|
|
@ -48,7 +48,7 @@ function execute() {
|
|||
};
|
||||
|
||||
// look through markdown headers of docs for titles and categories to translate
|
||||
let files = glob.sync(CWD + "/../docs/**");
|
||||
let files = glob.sync(CWD + "/../" + readMetadata.getDocsPath() + "/**");
|
||||
files.forEach(file => {
|
||||
const extension = path.extname(file);
|
||||
if (extension === ".md" || extension === ".markdown") {
|
||||
|
@ -91,7 +91,7 @@ function execute() {
|
|||
files.forEach(file => {
|
||||
if (!file.endsWith("-sidebars.json")) {
|
||||
if (file.endsWith("-sidebar.json")) {
|
||||
console.warn(`Skipping ${file}. Make sure your sidebar filenames follow this format: 'version-VERSION-sidebars.json'.`);
|
||||
console.warn(`Skipping ${file}. Make sure your sidebar filenames follow this format: 'version-VERSION-sidebars.json'.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue