( root: string, rel: string, body: string, position: 'start' | 'end' )
| 2789 | } |
| 2790 | |
| 2791 | export async function appendToNote( |
| 2792 | root: string, |
| 2793 | rel: string, |
| 2794 | body: string, |
| 2795 | position: 'start' | 'end' |
| 2796 | ): Promise<NoteMeta> { |
| 2797 | const abs = resolveSafe(root, rel) |
| 2798 | const folder = folderOf(root, abs) |
| 2799 | if (!folder) throw new Error(`Note not in a known folder: ${rel}`) |
| 2800 | const existing = await fs.readFile(abs, 'utf8') |
| 2801 | const trimmedAddition = body.replace(/\s+$/u, '') |
| 2802 | if (!trimmedAddition) return await readMeta(root, abs, folder) |
| 2803 | const next = |
| 2804 | position === 'end' |
| 2805 | ? `${existing}${existing.endsWith('\n') ? '' : '\n'}\n${trimmedAddition}\n` |
| 2806 | : `${trimmedAddition}\n\n${existing}` |
| 2807 | await fs.writeFile(abs, next, 'utf8') |
| 2808 | invalidateNoteMetaCache(root, rel) |
| 2809 | invalidateVaultTextSearchCache(root) |
| 2810 | return await readMeta(root, abs, folder) |
| 2811 | } |
| 2812 | |
| 2813 | export async function uniqueTitle(dir: string, baseTitle: string): Promise<string> { |
| 2814 | let candidate = baseTitle |
no test coverage detected