fix(server/utils): fix potentially "empty looking" title from getNoteTitle

when the noteMeta title consists of just spaces, it will fall back to "normal" handling again → instead of showing " " as title, which would be perceived as "empty"
This commit is contained in:
Panagiotis Papadopoulos 2025-01-31 21:52:26 +01:00
parent 46f28f4f09
commit 6e5e6989ed

View File

@ -182,7 +182,9 @@ export function removeTextFileExtension(filePath: string) {
} }
export function getNoteTitle(filePath: string, replaceUnderscoresWithSpaces: boolean, noteMeta?: NoteMeta) { export function getNoteTitle(filePath: string, replaceUnderscoresWithSpaces: boolean, noteMeta?: NoteMeta) {
if (noteMeta?.title) return noteMeta.title; const trimmedNoteMeta = noteMeta?.title?.trim();
if (trimmedNoteMeta) return trimmedNoteMeta;
const basename = path.basename(removeTextFileExtension(filePath)); const basename = path.basename(removeTextFileExtension(filePath));
return replaceUnderscoresWithSpaces ? basename.replace(/_/g, " ").trim() : basename; return replaceUnderscoresWithSpaces ? basename.replace(/_/g, " ").trim() : basename;
} }