mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
feat: throw FolderNotesApiAlreadyFolderNoteError if note is already a folder note
This commit is contained in:
parent
b6d947b248
commit
89bae42d0b
1 changed files with 14 additions and 0 deletions
14
src/api.ts
14
src/api.ts
|
|
@ -39,6 +39,8 @@ export interface FolderNotesApi {
|
|||
* Converts an existing note into the folder note for its parent folder.
|
||||
* Throws FolderNotesApiPathError if the path does not point to a note
|
||||
* inside a non-root folder.
|
||||
* Throws FolderNotesApiAlreadyFolderNoteError if the note is already
|
||||
* a folder note (e.g. aa/aa.md).
|
||||
*/
|
||||
convertNoteToFolderNote(notePath: string, options?: ConvertNoteToFolderNoteOptions): Promise<void>;
|
||||
}
|
||||
|
|
@ -53,6 +55,13 @@ export class FolderNotesApiPathError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
export class FolderNotesApiAlreadyFolderNoteError extends Error {
|
||||
constructor(readonly notePath: string) {
|
||||
super(`Note is already a folder note: ${notePath}`);
|
||||
this.name = 'FolderNotesApiAlreadyFolderNoteError';
|
||||
}
|
||||
}
|
||||
|
||||
export function getApi(plugin: FolderNotesPlugin): FolderNotesApi {
|
||||
return {
|
||||
version: API_VERSION,
|
||||
|
|
@ -85,6 +94,11 @@ async function convertNoteToFolderNote(
|
|||
throw new FolderNotesApiPathError(`Note must be inside a non-root folder: ${notePath}`, notePath);
|
||||
}
|
||||
|
||||
// Guard: already a folder note (e.g. aa/aa.md)
|
||||
if (getFolderNote(plugin, parentFolder.path) === file) {
|
||||
throw new FolderNotesApiAlreadyFolderNoteError(notePath);
|
||||
}
|
||||
|
||||
// Build the new folder path: sibling folder named after the note's basename
|
||||
const newFolderPath = parentFolder.path === ''
|
||||
? file.basename
|
||||
|
|
|
|||
Loading…
Reference in a new issue