avoid full split() in titleFromContent

This commit is contained in:
Horizontal42 2026-07-29 14:14:48 +03:00
parent 439eec2795
commit d66cad2dcf

View file

@ -50,9 +50,13 @@ function activeDoc(): DocMeta {
} }
function titleFromContent(text: string): string { function titleFromContent(text: string): string {
for (const line of text.split("\n")) { let start = 0;
const s = line.trim(); while (start < text.length) {
let end = text.indexOf("\n", start);
if (end === -1) end = text.length;
const s = text.slice(start, end).trim();
if (s.length > 0) return s.replace(/^#\s*/, "").slice(0, 30); if (s.length > 0) return s.replace(/^#\s*/, "").slice(0, 30);
start = end + 1;
} }
return t("untitled"); return t("untitled");
} }