fix: Title is duplicated on imported collections
This commit is contained in:
@@ -179,7 +179,6 @@ async function documentImporter({
|
|||||||
|
|
||||||
let title = fileName.replace(/\.[^/.]+$/, "");
|
let title = fileName.replace(/\.[^/.]+$/, "");
|
||||||
let text = await fileInfo.getMarkdown(content);
|
let text = await fileInfo.getMarkdown(content);
|
||||||
text = text.trim();
|
|
||||||
|
|
||||||
// find and extract emoji near the beginning of the document.
|
// find and extract emoji near the beginning of the document.
|
||||||
const regex = emojiRegex();
|
const regex = emojiRegex();
|
||||||
@@ -191,17 +190,18 @@ async function documentImporter({
|
|||||||
|
|
||||||
// If the first line of the imported text looks like a markdown heading
|
// If the first line of the imported text looks like a markdown heading
|
||||||
// then we can use this as the document title rather than the file name.
|
// then we can use this as the document title rather than the file name.
|
||||||
if (text.startsWith("# ")) {
|
if (text.trim().startsWith("# ")) {
|
||||||
const result = parseTitle(text);
|
const result = parseTitle(text);
|
||||||
title = result.title;
|
title = result.title;
|
||||||
text = text
|
text = text
|
||||||
|
.trim()
|
||||||
.replace(new RegExp(`#\\s+${escapeRegExp(title)}`), "")
|
.replace(new RegExp(`#\\s+${escapeRegExp(title)}`), "")
|
||||||
.trimStart();
|
.trimStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace any <br> generated by the turndown plugin with escaped newlines
|
// Replace any <br> generated by the turndown plugin with escaped newlines
|
||||||
// to match our hardbreak parser.
|
// to match our hardbreak parser.
|
||||||
text = text.replace(/<br>/gi, "\\n");
|
text = text.trim().replace(/<br>/gi, "\\n");
|
||||||
|
|
||||||
text = await DocumentHelper.replaceImagesWithAttachments(
|
text = await DocumentHelper.replaceImagesWithAttachments(
|
||||||
text,
|
text,
|
||||||
|
|||||||
Reference in New Issue
Block a user