MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / createNote

Function createNote

apps/desktop/src/main/vault.ts:2997–3015  ·  view source on GitHub ↗
(
  root: string,
  folder: NoteFolder,
  title?: string,
  subpath = ''
)

Source from the content-addressed store, hash-verified

2995}
2996
2997export async function createNote(
2998 root: string,
2999 folder: NoteFolder,
3000 title?: string,
3001 subpath = ''
3002): Promise<NoteMeta> {
3003 const base = sanitizeNoteTitle(title)
3004 const clean = subpath.replace(/^\/+|\/+$/g, '')
3005 const topRoot = await folderRoot(root, folder)
3006 const dir = clean ? resolveSafe(topRoot, clean) : topRoot
3007 await fs.mkdir(dir, { recursive: true })
3008 const finalTitle = await uniqueTitle(dir, base)
3009 const abs = path.join(dir, `${finalTitle}.md`)
3010 const body = `# ${finalTitle}\n\n`
3011 await fs.writeFile(abs, body, 'utf8')
3012 invalidateNoteMetaCache(root, toPosix(path.relative(root, abs)))
3013 invalidateVaultTextSearchCache(root)
3014 return await readMeta(root, abs, folder)
3015}
3016
3017// Create a new `.excalidraw` drawing seeded with an empty scene. Mirrors
3018// createNote (unique title, same folder/subpath resolution) but writes the

Callers 3

registerIpcFunction · 0.90
cmdCaptureFunction · 0.50
cmdCreateFunction · 0.50

Calls 8

sanitizeNoteTitleFunction · 0.85
invalidateNoteMetaCacheFunction · 0.85
folderRootFunction · 0.70
resolveSafeFunction · 0.70
uniqueTitleFunction · 0.70
toPosixFunction · 0.70
readMetaFunction · 0.70

Tested by

no test coverage detected