processIncludesForField processes import directives to extract a specific frontmatter field
(content, baseDir string, extractFunc func(string) (string, error), emptyValue string)
| 264 | |
| 265 | // processIncludesForField processes import directives to extract a specific frontmatter field |
| 266 | func processIncludesForField(content, baseDir string, extractFunc func(string) (string, error), emptyValue string) ([]string, string, error) { |
| 267 | // Fast path: skip scanner allocation when no include/import directives are present. |
| 268 | if !hasIncludeDirectives(content) { |
| 269 | return nil, content, nil |
| 270 | } |
| 271 | |
| 272 | scanner := bufio.NewScanner(strings.NewReader(content)) |
| 273 | var result bytes.Buffer |
| 274 | var results []string |
| 275 | |
| 276 | for scanner.Scan() { |
| 277 | line := scanner.Text() |
| 278 | |
| 279 | // Parse import directive |
| 280 | directive := ParseImportDirective(line) |
| 281 | if directive != nil { |
| 282 | fieldJSON, shouldSkip, err := extractFieldFromDirectiveForField(directive, baseDir, extractFunc) |
| 283 | if err != nil { |
| 284 | return nil, "", err |
| 285 | } |
| 286 | if shouldSkip { |
| 287 | continue |
| 288 | } |
| 289 | if fieldJSON != "" && fieldJSON != emptyValue { |
| 290 | results = append(results, fieldJSON) |
| 291 | } |
| 292 | } else { |
| 293 | // Regular line, just pass through |
| 294 | result.WriteString(line + "\n") |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | return results, result.String(), nil |
| 299 | } |
| 300 | |
| 301 | func extractFieldFromDirectiveForField( |
| 302 | directive *ImportDirectiveMatch, |
no test coverage detected