mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
DOCUMENTATION: Support showing images in markdown docs (#2207)
This commit is contained in:
@@ -3,13 +3,18 @@ const path = require("path");
|
||||
|
||||
const docFiles = [];
|
||||
const nsDocFiles = [];
|
||||
const docImagesFiles = [];
|
||||
const docRoot = path.resolve(__dirname, "../../src/Documentation/doc");
|
||||
const markdownRoot = path.resolve(__dirname, "../../markdown");
|
||||
const docImagesRoot = path.resolve(__dirname, "../../src/Documentation/images");
|
||||
const addFileToListOfDocPages = (files, root, filePath) => {
|
||||
// Windows path uses "\", so we need to replace it with "/".
|
||||
files.push(path.relative(root, filePath).replace(/\\/g, "/"));
|
||||
};
|
||||
const processDir = (dir) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
return;
|
||||
}
|
||||
console.log(dir);
|
||||
for (const file of fs.readdirSync(dir)) {
|
||||
const filePath = path.join(dir, file);
|
||||
@@ -19,14 +24,17 @@ const processDir = (dir) => {
|
||||
}
|
||||
if (filePath.startsWith(docRoot)) {
|
||||
addFileToListOfDocPages(docFiles, docRoot, filePath);
|
||||
} else {
|
||||
} else if (filePath.startsWith(markdownRoot)) {
|
||||
addFileToListOfDocPages(nsDocFiles, markdownRoot, filePath);
|
||||
} else {
|
||||
addFileToListOfDocPages(docImagesFiles, docImagesRoot, filePath);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
processDir(docRoot);
|
||||
processDir(markdownRoot);
|
||||
processDir(docImagesRoot);
|
||||
|
||||
/**
|
||||
* When importing NS API markdown files, we use "nsDoc_something" instead of file<number> like other docs. Currently,
|
||||
@@ -46,9 +54,10 @@ processDir(markdownRoot);
|
||||
* in src\Documentation\doc, but we rarely add or remove files in it, so it's not a big deal. Checking ~60 lines is also
|
||||
* much easier than checking ~1400 lines.
|
||||
*/
|
||||
const autogeneratedContent = `// THIS FILE IS AUTOGENERATED. DO NOT EDIT IT MANUALLY.
|
||||
let autogeneratedContent = `// THIS FILE IS AUTOGENERATED. DO NOT EDIT IT MANUALLY.
|
||||
${docFiles.map((f, i) => `import file${i} from "./doc/${f}?raw";`).join("\n")}
|
||||
${nsDocFiles.map((f, i) => `import nsDoc_${f.replaceAll(".", "_")} from "../../markdown/${f}?raw";`).join("\n")}
|
||||
${docImagesFiles.map((f, i) => `import docImages_${f.replaceAll(".", "_")} from "./images/${f}";`).join("\n")}
|
||||
|
||||
export const AllPages: Record<string, string> = {};
|
||||
${docFiles.map((f, i) => `AllPages["${f}"] = file${i};`).join("\n")}
|
||||
@@ -57,7 +66,14 @@ ${nsDocFiles.map((f, i) => `AllPages["nsDoc/${f}"] = nsDoc_${f.replaceAll(".", "
|
||||
export const nsApiPages = Object.keys(AllPages)
|
||||
.filter((page) => page.startsWith("nsDoc"))
|
||||
.map((page) => page.replace("nsDoc/", ""));
|
||||
|
||||
export const DocImages: Record<string, string> = {};
|
||||
`;
|
||||
if (docImagesFiles.length > 0) {
|
||||
autogeneratedContent += `
|
||||
${docImagesFiles.map((f, i) => `DocImages["${f}"] = docImages_${f.replaceAll(".", "_")};`).join("\n")}
|
||||
`;
|
||||
}
|
||||
|
||||
fs.writeFile(path.resolve(__dirname, "../../src/Documentation/pages.ts"), autogeneratedContent, (err) => {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user