Skip to content

Commit 6e0f38a

Browse files
committed
fix font scanning
1 parent 1839869 commit 6e0f38a

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

app.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const DOMPurify = createDOMPurify(window);
9595
const app = express();
9696
app.set("trust proxy", true);
9797

98-
import { scanFiles, preParse, manipulateHtml, wrapInPage, wrapInReveal, splitForReveal, parseFirstLineForPermissions } from "./obsidian.js";
98+
import { scanFiles, scanFonts, preParse, manipulateHtml, wrapInPage, wrapInReveal, splitForReveal, parseFirstLineForPermissions } from "./obsidian.js";
9999
import { hasSomeRoles } from "./utils.js";
100100

101101
async function sanitizeAndParseMarkdown(data, req) {
@@ -300,7 +300,9 @@ initKeycloak(app).then(() => {
300300

301301
const basePath = process.env.NEXT_PUBLIC_IS_APP_FOLDER ? '/app/' : '.';
302302
scanFiles("md/", path.join(basePath, "md")).then(() => {
303-
app.listen(process.env.NEXT_PUBLIC_PORT, "0.0.0.0");
303+
scanFonts(path.join(basePath, "assets")).then(() => {
304+
app.listen(process.env.NEXT_PUBLIC_PORT, "0.0.0.0");
305+
});
304306
});
305307

306308
// If file is not found, redirect to the start page.

obsidian.js

+46
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,52 @@ function makeSafeForCSS(name) {
164164
});
165165
}
166166

167+
export async function scanFonts(dir, root = dir) {
168+
const files = fs.readdirSync(dir);
169+
170+
for (const file of files) {
171+
try {
172+
if (dir && file) {
173+
// Check if dir and file are not null
174+
const filePath = path.join(dir, file);
175+
const isDirectory = fs.statSync(filePath).isDirectory();
176+
if (isDirectory) {
177+
const nmods = process.env.NEXT_PUBLIC_IS_APP_FOLDER
178+
? "/app/node_modules"
179+
: "node_modules";
180+
const slides = process.env.NEXT_PUBLIC_IS_APP_FOLDER
181+
? "/app/slides"
182+
: "slides";
183+
if (
184+
filePath.startsWith(".") ||
185+
filePath.startsWith(nmods) ||
186+
filePath.startsWith(slides)
187+
)
188+
continue;
189+
scanFonts(filePath, root);
190+
} else {
191+
// All other files.
192+
const fileName = path.basename(file);
193+
const relativePath = path.relative(root, filePath);
194+
const p = relativePath.replace(/\\/g, "/");
195+
if (p.startsWith("main-fonts/")) {
196+
const fontName = path.basename(file, ".ttf");
197+
mainFonts[fontName] = "assets/" + p;
198+
mainFontsArray.push(fontName);
199+
}
200+
if (p.startsWith("nav-fonts/")) {
201+
const fontName = path.basename(file, ".ttf");
202+
navFonts[fontName] = "assets/" + p;
203+
navFontsArray.push(fontName);
204+
}
205+
}
206+
}
207+
} catch (err) {
208+
console.error(`Error reading file while scanning fonts ${file}`, err);
209+
}
210+
}
211+
}
212+
167213
/**
168214
* If it's the root dir, dirPrefix should be an empty string.
169215
*/

0 commit comments

Comments
 (0)