[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:
Joel Marcey 2017-11-08 20:16:05 -08:00
parent 9f32a28d32
commit dc0c1390c4
5 changed files with 24 additions and 12 deletions

View file

@ -129,7 +129,7 @@ function execute() {
} }
} else { } else {
if (metadata.language === "en") { if (metadata.language === "en") {
file = CWD + "/../docs/" + metadata.source; file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
} else { } else {
file = file =
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source; CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
@ -219,9 +219,9 @@ function execute() {
}); });
// copy docs assets if they exist // copy docs assets if they exist
if (fs.existsSync(CWD + "/../docs/assets")) { if (fs.existsSync(CWD + "/../" + readMetadata.getDocsPath() + "/assets")) {
fs.copySync( fs.copySync(
CWD + "/../docs/assets", CWD + "/../" + readMetadata.getDocsPath() + "/assets",
CWD + "/build/" + siteConfig.projectName + "/docs/assets" CWD + "/build/" + siteConfig.projectName + "/docs/assets"
); );
} }

View file

@ -16,6 +16,8 @@ const versionFallback = require("./versionFallback.js");
const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json"); const ENABLE_VERSIONING = fs.existsSync(CWD + "/versions.json");
let languages; let languages;
if (fs.existsSync(CWD + "/languages.js")) { if (fs.existsSync(CWD + "/languages.js")) {
languages = require(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 // returns map from id to object containing sidebar ordering info
function readSidebar() { function readSidebar() {
let allSidebars; let allSidebars;
@ -114,7 +125,7 @@ function extractMetadata(content) {
function processMetadata(file) { function processMetadata(file) {
const result = extractMetadata(fs.readFileSync(file, "utf8")); const result = extractMetadata(fs.readFileSync(file, "utf8"));
const regexSubFolder = /docs\/(.*)\/.*/; let regexSubFolder = new RegExp("/" + getDocsPath() + "\/(.*)\/.*/");
let language = "en"; let language = "en";
const match = regexSubFolder.exec(file); const match = regexSubFolder.exec(file);
@ -202,7 +213,7 @@ function generateMetadataDocs() {
const defaultMetadatas = {}; const defaultMetadatas = {};
// metadata for english files // metadata for english files
let files = glob.sync(CWD + "/../docs/**"); let files = glob.sync(CWD + "/../" + getDocsPath() + "/**");
files.forEach(file => { files.forEach(file => {
let language = "en"; let language = "en";
@ -389,6 +400,7 @@ function generateMetadataBlog() {
} }
module.exports = { module.exports = {
getDocsPath,
readSidebar, readSidebar,
extractMetadata, extractMetadata,
processMetadata, processMetadata,

View file

@ -177,7 +177,7 @@ function execute(port) {
} }
} else { } else {
if (metadata.language === "en") { if (metadata.language === "en") {
file = CWD + "/../docs/" + metadata.source; file = CWD + "/../" + readMetadata.getDocsPath() + "/" + metadata.source;
} else { } else {
file = file =
CWD + "/translated_docs/" + metadata.language + "/" + metadata.source; CWD + "/translated_docs/" + metadata.language + "/" + metadata.source;
@ -485,7 +485,7 @@ function execute(port) {
// serve static assets from these locations // serve static assets from these locations
app.use( app.use(
siteConfig.baseUrl + "docs/assets/", siteConfig.baseUrl + "docs/assets/",
express.static(CWD + "/../docs/assets") express.static(CWD + "/../" + readMetadata.getDocsPath() + "/assets")
); );
app.use( app.use(
siteConfig.baseUrl + "blog/assets/", siteConfig.baseUrl + "blog/assets/",

View file

@ -65,7 +65,7 @@ const versionFolder = CWD + "/versioned_docs/version-" + version;
mkdirp.sync(versionFolder); mkdirp.sync(versionFolder);
// copy necessary files to new version, changing some of its metadata to reflect the versioning // 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 => { files.forEach(file => {
const ext = path.extname(file); const ext = path.extname(file);
if (ext !== ".md" && ext !== ".markdown") { if (ext !== ".md" && ext !== ".markdown") {

View file

@ -48,7 +48,7 @@ function execute() {
}; };
// look through markdown headers of docs for titles and categories to translate // 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 => { files.forEach(file => {
const extension = path.extname(file); const extension = path.extname(file);
if (extension === ".md" || extension === ".markdown") { if (extension === ".md" || extension === ".markdown") {