| … | … | @@ -15,28 +15,26 @@ export class YAMLHelper { |
| 15 | 15 | */ |
| 16 | 16 | static create(metadata, content) { |
| 17 | 17 | const lines = [] |
| 18 | | |
| 18 | |
| 19 | // Start with opening delimiter (standard YAML frontmatter) |
| 20 | lines.push('---') |
| 21 | |
| 19 | 22 | if (metadata.name) { |
| 20 | 23 | lines.push(`name: ${metadata.name}`) |
| 21 | 24 | } |
| 22 | | |
| 25 | |
| 23 | 26 | if (metadata.image) { |
| 24 | 27 | lines.push(`image: ${metadata.image}`) |
| 25 | 28 | } |
| 26 | | |
| 29 | |
| 27 | 30 | if (metadata.previous) { |
| 28 | 31 | lines.push(`previous: ${metadata.previous}`) |
| 29 | 32 | } |
| 30 | | |
| 31 | | if (lines.length === 0) { |
| 32 | | // No metadata, just return content |
| 33 | | return content |
| 34 | | } |
| 35 | | |
| 36 | | // Add separator and content |
| 33 | |
| 34 | // Add closing delimiter and content |
| 37 | 35 | lines.push('---') |
| 38 | 36 | lines.push(content) |
| 39 | | |
| 37 | |
| 40 | 38 | return lines.join('\n') |
| 41 | 39 | } |
| 42 | 40 | |
| … | … | @@ -45,7 +43,7 @@ export class YAMLHelper { |
| 45 | 43 | */ |
| 46 | 44 | static parse(yaml) { |
| 47 | 45 | const parts = yaml.split('\n---\n') |
| 48 | | |
| 46 | |
| 49 | 47 | if (parts.length === 1) { |
| 50 | 48 | // No metadata, just content |
| 51 | 49 | return { |
| … | … | @@ -53,21 +51,24 @@ export class YAMLHelper { |
| 53 | 51 | content: yaml |
| 54 | 52 | } |
| 55 | 53 | } |
| 56 | | |
| 54 | |
| 57 | 55 | const [frontMatter, ...contentParts] = parts |
| 58 | 56 | const content = contentParts.join('\n---\n') |
| 59 | | |
| 57 | |
| 60 | 58 | const metadata = {} |
| 61 | 59 | const lines = frontMatter.split('\n') |
| 62 | | |
| 60 | |
| 63 | 61 | for (const line of lines) { |
| 62 | // Skip the opening --- delimiter |
| 63 | if (line.trim() === '---') continue |
| 64 | |
| 64 | 65 | const match = line.match(/^(\w+):\s*(.+)$/) |
| 65 | 66 | if (match) { |
| 66 | 67 | const [, key, value] = match |
| 67 | 68 | metadata[key] = value |
| 68 | 69 | } |
| 69 | 70 | } |
| 70 | | |
| 71 | |
| 71 | 72 | return { metadata, content } |
| 72 | 73 | } |
| 73 | 74 | } |