Skip to content

Commit

Permalink
flatten md-directory into root for md-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
guFalcon committed Apr 16, 2024
1 parent a4faf73 commit d86905a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

Expand Down
12 changes: 9 additions & 3 deletions obsidian.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) => {
Expand All @@ -174,6 +178,7 @@ export async function scanFiles(dir, root = dir) {
}
return {
[file]: {
dirPrefix: dirPrefix,
path: file,
pathWithoutExt: pwe,
folders: folders,
Expand All @@ -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),
},
};
})
Expand Down Expand Up @@ -793,7 +798,8 @@ function insertDirFolder(folder, j) {

function insertDirLink(file, req, indent, i, files) {
let r = "";
r += `<a href="/${file.path}" class="${
console.log(file);
r += `<a href="/${file.dirPrefix + file.path}" class="${
"/" + file.path === decodeURIComponent(req.path) ? "highlight" : ""
}">${indentStringFor(file.lastFolder === "" ? 0 : indent)}${
file.fileNameWithoutExtension
Expand Down

0 comments on commit d86905a

Please sign in to comment.