( root: string, folder: NoteFolder, title?: string, subpath = '', body?: string )
| 600 | } |
| 601 | |
| 602 | export async function createNote( |
| 603 | root: string, |
| 604 | folder: NoteFolder, |
| 605 | title?: string, |
| 606 | subpath = '', |
| 607 | body?: string |
| 608 | ): Promise<NoteMeta> { |
| 609 | if (folder === 'trash') throw new Error('Refusing to create a note directly in trash/') |
| 610 | const base = sanitizeTitle(title ?? 'Untitled') |
| 611 | const clean = subpath.replace(/^\/+|\/+$/g, '') |
| 612 | const folderAbs = await folderRoot(root, folder) |
| 613 | const dir = clean |
| 614 | ? resolveSafe(folderAbs, clean) |
| 615 | : folderAbs |
| 616 | await fs.mkdir(dir, { recursive: true }) |
| 617 | const finalTitle = await uniqueTitle(dir, base) |
| 618 | const abs = path.join(dir, `${finalTitle}.md`) |
| 619 | const content = body ?? `# ${finalTitle}\n\n` |
| 620 | await fs.writeFile(abs, content, 'utf8') |
| 621 | return await readMeta(root, abs, folder) |
| 622 | } |
| 623 | |
| 624 | export async function renameNote(root: string, rel: string, nextTitle: string): Promise<NoteMeta> { |
| 625 | const abs = resolveSafe(root, rel) |
no test coverage detected