mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 02:12:00 +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 {
|
||||
for (const line of text.split("\n")) {
|
||||
const s = line.trim();
|
||||
let start = 0;
|
||||
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);
|
||||
start = end + 1;
|
||||
}
|
||||
return t("untitled");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue