( directive *ImportDirectiveMatch, baseDir string, extractFunc func(string) (string, error), )
| 299 | } |
| 300 | |
| 301 | func extractFieldFromDirectiveForField( |
| 302 | directive *ImportDirectiveMatch, |
| 303 | baseDir string, |
| 304 | extractFunc func(string) (string, error), |
| 305 | ) (string, bool, error) { |
| 306 | filePath := includeDirectiveFilePath(directive.Path) |
| 307 | fullPath, err := ResolveIncludePath(filePath, baseDir, nil) |
| 308 | if err != nil { |
| 309 | if directive.IsOptional { |
| 310 | return "", true, nil |
| 311 | } |
| 312 | return "", false, fmt.Errorf("failed to resolve required include '%s': %w", filePath, err) |
| 313 | } |
| 314 | |
| 315 | fileContent, err := readFileFunc(fullPath) |
| 316 | if err != nil { |
| 317 | return "", false, fmt.Errorf("failed to read included file '%s': %w", fullPath, err) |
| 318 | } |
| 319 | |
| 320 | fieldJSON, err := extractFunc(string(fileContent)) |
| 321 | if err != nil { |
| 322 | return "", false, fmt.Errorf("failed to extract field from '%s': %w", fullPath, err) |
| 323 | } |
| 324 | |
| 325 | return fieldJSON, false, nil |
| 326 | } |
| 327 | |
| 328 | func includeDirectiveFilePath(includePath string) string { |
| 329 | // Note: section references are ignored for frontmatter field extraction. |
no test coverage detected