ParseProgress reads and parses a progress.md file. Returns a map of story ID -> list of progress entries (one per session/date).
(path string)
| 28 | // ParseProgress reads and parses a progress.md file. |
| 29 | // Returns a map of story ID -> list of progress entries (one per session/date). |
| 30 | func ParseProgress(path string) (map[string][]ProgressEntry, error) { |
| 31 | f, err := os.Open(path) |
| 32 | if err != nil { |
| 33 | if os.IsNotExist(err) { |
| 34 | return nil, nil |
| 35 | } |
| 36 | return nil, err |
| 37 | } |
| 38 | defer f.Close() |
| 39 | |
| 40 | result := make(map[string][]ProgressEntry) |
| 41 | var current *ProgressEntry |
| 42 | var lines []string |
| 43 | |
| 44 | flush := func() { |
| 45 | if current != nil && len(lines) > 0 { |
| 46 | current.Content = strings.Join(lines, "\n") |
| 47 | result[current.StoryID] = append(result[current.StoryID], *current) |
| 48 | } |
| 49 | current = nil |
| 50 | lines = nil |
| 51 | } |
| 52 | |
| 53 | scanner := bufio.NewScanner(f) |
| 54 | for scanner.Scan() { |
| 55 | line := scanner.Text() |
| 56 | |
| 57 | // Check for section separator |
| 58 | if strings.TrimSpace(line) == "---" { |
| 59 | flush() |
| 60 | continue |
| 61 | } |
| 62 | |
| 63 | // Check for story header |
| 64 | if matches := storyHeaderRegex.FindStringSubmatch(line); matches != nil { |
| 65 | flush() |
| 66 | current = &ProgressEntry{ |
| 67 | Date: matches[1], |
| 68 | StoryID: matches[2], |
| 69 | } |
| 70 | continue |
| 71 | } |
| 72 | |
| 73 | // Collect lines within a story section |
| 74 | if current != nil { |
| 75 | lines = append(lines, line) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Flush the last entry |
| 80 | flush() |
| 81 | |
| 82 | if err := scanner.Err(); err != nil { |
| 83 | return result, err |
| 84 | } |
| 85 | return result, nil |
| 86 | } |
| 87 |
no outgoing calls