mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 21:31:59 +03:00
avoid full split() in titleFromContent
This commit is contained in:
parent
439eec2795
commit
d66cad2dcf
1 changed files with 6 additions and 2 deletions
|
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue