prepend_to_note
Add content to the beginning of an Obsidian note while preserving frontmatter structure.
Instructions
Prepend content to a note, after frontmatter if present
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Relative path to the note | |
| content | Yes | Content to prepend |
Implementation Reference
- src/lib/vault.ts:96-118 (handler)The implementation of prependToNote which inserts content at the beginning of a markdown file, optionally after existing YAML frontmatter.
export async function prependToNote( vaultPath: string, relativePath: string, content: string, ): Promise<void> { const fullPath = resolveVaultPath(vaultPath, relativePath); const existing = await fs.readFile(fullPath, "utf-8"); // Detect frontmatter block (starts with --- on first line) const frontmatterMatch = existing.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/); let result: string; if (frontmatterMatch) { const frontmatter = frontmatterMatch[0]; const rest = existing.slice(frontmatter.length); const separator = frontmatter.endsWith("\n") ? "" : "\n"; result = frontmatter + separator + content + "\n" + rest; } else { result = content + "\n" + existing; } await fs.writeFile(fullPath, result, "utf-8"); }