| 108 | } |
| 109 | |
| 110 | function composeBody( |
| 111 | title: string | undefined, |
| 112 | body: string | undefined, |
| 113 | tags: string[] |
| 114 | ): string | undefined { |
| 115 | if (body == null && tags.length === 0) return undefined |
| 116 | const heading = title ? `# ${title}\n\n` : '' |
| 117 | const tagLine = tags.length > 0 ? tags.map((t) => `#${t}`).join(' ') + '\n\n' : '' |
| 118 | const bodyText = body ?? '' |
| 119 | const out = `${heading}${tagLine}${bodyText}` |
| 120 | return out.endsWith('\n') ? out : out + '\n' |
| 121 | } |
| 122 | |
| 123 | export async function cmdWrite(vault: string, args: ParsedArgs): Promise<void> { |
| 124 | const rel = requirePath(args) |