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

Function prependToNote

apps/desktop/src/mcp/vault-ops.ts:1106–1123  ·  view source on GitHub ↗
(root: string, rel: string, text: string)

Source from the content-addressed store, hash-verified

1104}
1105
1106export async function prependToNote(root: string, rel: string, text: string): Promise<NoteMeta> {
1107 const abs = resolveSafe(root, rel)
1108 const body = await fs.readFile(abs, 'utf8')
1109 const normalized = body.replace(/\r\n/g, '\n')
1110 const fm = normalized.match(FRONTMATTER_RE)
1111 const snippet = trimTrailingNewlines(text) + '\n\n'
1112 let next: string
1113 if (fm) {
1114 const after = normalized.slice(fm[0].length)
1115 next = fm[0] + snippet + after
1116 } else {
1117 next = snippet + normalized
1118 }
1119 await fs.writeFile(abs, next, 'utf8')
1120 const folder = folderOf(root, abs)
1121 if (!folder) throw new Error(`Note not in a known folder: ${rel}`)
1122 return await readMeta(root, abs, folder)
1123}
1124
1125export async function replaceInNote(
1126 root: string,

Callers 2

cmdPrependFunction · 0.85
server.tsFile · 0.85

Calls 4

trimTrailingNewlinesFunction · 0.85
resolveSafeFunction · 0.70
folderOfFunction · 0.70
readMetaFunction · 0.70

Tested by

no test coverage detected