updateFieldInFrontmatterFallback implements the original behavior as a fallback
(result *parser.FrontmatterResult, fieldName, fieldValue string)
| 107 | |
| 108 | // updateFieldInFrontmatterFallback implements the original behavior as a fallback |
| 109 | func updateFieldInFrontmatterFallback(result *parser.FrontmatterResult, fieldName, fieldValue string) (string, error) { |
| 110 | // Initialize frontmatter if it doesn't exist |
| 111 | if result.Frontmatter == nil { |
| 112 | result.Frontmatter = make(map[string]any) |
| 113 | } |
| 114 | |
| 115 | // Update the field |
| 116 | result.Frontmatter[fieldName] = fieldValue |
| 117 | |
| 118 | // Convert back to YAML with proper field ordering |
| 119 | updatedFrontmatter, err := workflow.MarshalWithFieldOrder(result.Frontmatter, constants.PriorityWorkflowFields) |
| 120 | if err != nil { |
| 121 | return "", fmt.Errorf("failed to marshal updated frontmatter: %w", err) |
| 122 | } |
| 123 | |
| 124 | // Clean up quoted keys - replace "on": with on: at the start of a line |
| 125 | frontmatterStr := strings.TrimSuffix(string(updatedFrontmatter), "\n") |
| 126 | frontmatterStr = workflow.UnquoteYAMLKey(frontmatterStr, "on") |
| 127 | |
| 128 | // Reconstruct the file |
| 129 | var lines []string |
| 130 | lines = append(lines, "---") |
| 131 | if frontmatterStr != "" { |
| 132 | lines = append(lines, strings.Split(frontmatterStr, "\n")...) |
| 133 | } |
| 134 | lines = append(lines, "---") |
| 135 | if result.Markdown != "" { |
| 136 | lines = append(lines, result.Markdown) |
| 137 | } |
| 138 | |
| 139 | return strings.Join(lines, "\n"), nil |
| 140 | } |
| 141 | |
| 142 | // addFieldToFrontmatter adds a new field to the frontmatter while preserving formatting. |
| 143 | // This is used when we know the field doesn't exist yet. |
no test coverage detected