findFrontmatterBounds finds the start and end indices of frontmatter in file lines Returns: startIdx (-1 if not found), endIdx (-1 if not found), frontmatterContent
(lines []string)
| 257 | // findFrontmatterBounds finds the start and end indices of frontmatter in file lines |
| 258 | // Returns: startIdx (-1 if not found), endIdx (-1 if not found), frontmatterContent |
| 259 | func findFrontmatterBounds(lines []string) (startIdx int, endIdx int, frontmatterContent string) { |
| 260 | schemaErrorsLog.Printf("Finding frontmatter bounds in %d lines", len(lines)) |
| 261 | startIdx = -1 |
| 262 | endIdx = -1 |
| 263 | |
| 264 | // Look for the opening "---" |
| 265 | for i, line := range lines { |
| 266 | trimmed := strings.TrimSpace(line) |
| 267 | if trimmed == "---" { |
| 268 | startIdx = i |
| 269 | break |
| 270 | } |
| 271 | // Skip empty lines and comments at the beginning |
| 272 | if trimmed != "" && !strings.HasPrefix(trimmed, "#") { |
| 273 | // Found non-empty, non-comment line before "---" - no frontmatter |
| 274 | return -1, -1, "" |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | if startIdx == -1 { |
| 279 | schemaErrorsLog.Print("No frontmatter opening delimiter found") |
| 280 | return -1, -1, "" |
| 281 | } |
| 282 | |
| 283 | // Look for the closing "---" |
| 284 | for i := startIdx + 1; i < len(lines); i++ { |
| 285 | trimmed := strings.TrimSpace(lines[i]) |
| 286 | if trimmed == "---" { |
| 287 | endIdx = i |
| 288 | break |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | if endIdx == -1 { |
| 293 | // No closing "---" found |
| 294 | schemaErrorsLog.Print("No frontmatter closing delimiter found") |
| 295 | return -1, -1, "" |
| 296 | } |
| 297 | schemaErrorsLog.Printf("Found frontmatter bounds: start=%d end=%d", startIdx, endIdx) |
| 298 | |
| 299 | // Extract frontmatter content between the markers |
| 300 | frontmatterLines := lines[startIdx+1 : endIdx] |
| 301 | frontmatterContent = strings.Join(frontmatterLines, "\n") |
| 302 | |
| 303 | return startIdx, endIdx, frontmatterContent |
| 304 | } |
| 305 | |
| 306 | // knownFieldValidValues maps well-known JSON schema paths to a human-readable description |
| 307 | // of the valid values / children for that field. Used to append helpful hints when an |