* Parse YAML front-matter from a capture file
(content: string)
| 65 | * Parse YAML front-matter from a capture file |
| 66 | */ |
| 67 | function parseFrontMatter(content: string): { frontMatter: CaptureFrontMatter; body: string } { |
| 68 | const frontMatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/ |
| 69 | const match = content.match(frontMatterRegex) |
| 70 | |
| 71 | if (!match) { |
| 72 | // No front-matter, return defaults |
| 73 | return { |
| 74 | frontMatter: { |
| 75 | sequence: 0, |
| 76 | label: null, |
| 77 | timestamp: new Date().toISOString(), |
| 78 | after_command: null, |
| 79 | dimensions: { width: 'unknown', height: 'unknown' }, |
| 80 | }, |
| 81 | body: content, |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | const frontMatter = yaml.load(match[1]) as CaptureFrontMatter |
| 86 | return { frontMatter, body: match[2] } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Check if a filename matches capture file patterns: |