Skip to content

Build your personal knowledge base with Trilium Notes

fix(import): keep untitled notes untitled when importing a Trilium export

Elian Doran50aa0a6bd783
diff --git a/packages/trilium-core/src/services/utils/index.spec.ts b/packages/trilium-core/src/services/utils/index.spec.ts
index 1c218e4726..8aea63642e 100644
--- a/packages/trilium-core/src/services/utils/index.spec.ts
+++ b/packages/trilium-core/src/services/utils/index.spec.ts
@@ -388,14 +388,19 @@ describe("#getNoteTitle", () => {
"some other title"
],
[
- "when a noteMeta object is passed, but the title prop is empty, it should try to handle the filename as if no noteMeta was passed",
- [ "test_file.md", true, { title: "" } ],
- "test file"
+ "when a noteMeta object is passed with an empty title, it should keep the note untitled",
+ [ "note.html", true, { title: "" } ],
+ ""
],
[
- "when a noteMeta object is passed, but the title prop is empty, it should try to handle the filename as if no noteMeta was passed",
- [ "test_file.json", false, { title: " " } ],
- "test_file.json"
+ "when a noteMeta object is passed with a blank title, it should keep the note untitled",
+ [ "1_note.html", false, { title: " " } ],
+ ""
+ ],
+ [
+ "when a noteMeta object is passed without a title, it should handle the filename as if no noteMeta was passed",
+ [ "test_file.md", true, { mime: "text/markdown" } ],
+ "test file"
]
];
diff --git a/packages/trilium-core/src/services/utils/index.ts b/packages/trilium-core/src/services/utils/index.ts
index ccf12b01d3..568ace46e9 100644
--- a/packages/trilium-core/src/services/utils/index.ts
+++ b/packages/trilium-core/src/services/utils/index.ts
@@ -390,8 +390,8 @@ export function removeFileExtension(filePath: string, mime?: string) {
}
export function getNoteTitle(filePath: string, replaceUnderscoresWithSpaces: boolean, noteMeta?: NoteMeta) {
- const trimmedNoteMeta = noteMeta?.title?.trim();
- if (trimmedNoteMeta) return trimmedNoteMeta;
+ // An empty title in `!!!meta.json` is an untitled note, not a missing title.
+ if (noteMeta?.title !== undefined) return noteMeta.title.trim();
const fileBasename = basename(removeFileExtension(filePath, noteMeta?.mime));
return replaceUnderscoresWithSpaces ? fileBasename.replace(/_/g, " ").trim() : fileBasename;