From d86905aa698d4f272141cd8954dbb9cf5ce5105a Mon Sep 17 00:00:00 2001 From: Gerald Date: Tue, 16 Apr 2024 08:15:34 +0200 Subject: [PATCH] flatten md-directory into root for md-viewer --- app.js | 2 +- obsidian.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index a49b4c0..4326581 100644 --- a/app.js +++ b/app.js @@ -299,7 +299,7 @@ initKeycloak(app).then(() => { }); const basePath = process.env.NEXT_PUBLIC_IS_APP_FOLDER ? '/app/' : '.'; - scanFiles(basePath).then(() => { + scanFiles("md/", path.join(basePath, "md")).then(() => { app.listen(process.env.NEXT_PUBLIC_PORT, "0.0.0.0"); }); diff --git a/obsidian.js b/obsidian.js index bfacf1a..cc7b3b7 100644 --- a/obsidian.js +++ b/obsidian.js @@ -103,6 +103,7 @@ export const callouts = { export const mdFilesMap = {}; export const filesMap = {}; export const mdFilesDir = {}; +export const mdFilesDirOnHdd = {}; export let mdFilesDirStructure = {}; export const mainFonts = {}; export const mainFontsArray = []; @@ -162,7 +163,10 @@ function makeSafeForCSS(name) { }); } -export async function scanFiles(dir, root = dir) { +/** + * If it's the root dir, dirPrefix should be an empty string. + */ +export async function scanFiles(dirPrefix, dir, root = dir) { scanFilesInternal(dir, root); let mdFiles = await Promise.all( Object.keys(mdFilesDir).map(async (file) => { @@ -174,6 +178,7 @@ export async function scanFiles(dir, root = dir) { } return { [file]: { + dirPrefix: dirPrefix, path: file, pathWithoutExt: pwe, folders: folders, @@ -183,7 +188,7 @@ export async function scanFiles(dir, root = dir) { fileNameWithoutExtension: pwe.split("/").pop().split(".")[0], lastFolder: pwe.split("/").slice(-2, -1)[0] || "", cssName: makeSafeForCSS(folders), - permissions: await getPermissionsFor(file), + permissions: await getPermissionsFor(dirPrefix + file), }, }; }) @@ -793,7 +798,8 @@ function insertDirFolder(folder, j) { function insertDirLink(file, req, indent, i, files) { let r = ""; - r += `${indentStringFor(file.lastFolder === "" ? 0 : indent)}${ file.fileNameWithoutExtension