Extract YAML frontmatter from a markdown string. Returns {} if none found.
(content)
| 173 | // ── Campaign helpers ─────────────────────────────────────────────────────────── |
| 174 | |
| 175 | /** Extract YAML frontmatter from a markdown string. Returns {} if none found. */ |
| 176 | function parseFrontmatter(content) { |
| 177 | const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---/); |
| 178 | if (!m) return {}; |
| 179 | const result = {}; |
| 180 | for (const line of m[1].split(/\r?\n/)) { |
| 181 | const kv = line.match(/^(\w+):\s*(.*)$/); |
| 182 | if (kv) { |
| 183 | const val = kv[2].trim().replace(/^["']|["']$/g, ''); |
| 184 | result[kv[1]] = isNaN(val) ? val : Number(val); |
| 185 | } |
| 186 | } |
| 187 | return result; |
| 188 | } |
| 189 | |
| 190 | function makeCampaignFile(name, status = 'active', phaseCount = 3, currentPhase = 1) { |