assembleSession turns the in-memory draft into (summary, tags, body). The session-summary entry (if any) becomes the file header + the index record; everything else is grouped by Kind into sections of the body.
()
| 223 | // The session-summary entry (if any) becomes the file header + the index |
| 224 | // record; everything else is grouped by Kind into sections of the body. |
| 225 | func (s *SessionFiles) assembleSession() (summary string, tags []string, body string) { |
| 226 | summary = "(no summary)" |
| 227 | var rest []Entry |
| 228 | for _, e := range s.draft { |
| 229 | if e.Kind == KindSessionSummary { |
| 230 | summary = e.Content |
| 231 | tags = e.Tags |
| 232 | continue |
| 233 | } |
| 234 | rest = append(rest, e) |
| 235 | } |
| 236 | |
| 237 | var b strings.Builder |
| 238 | fmt.Fprintf(&b, "# %s\n", s.sessionStart.Format("2006-01-02 15:04")) |
| 239 | if len(tags) > 0 { |
| 240 | fmt.Fprintf(&b, "tags: %s\n", strings.Join(tags, ", ")) |
| 241 | } |
| 242 | fmt.Fprintln(&b) |
| 243 | fmt.Fprintln(&b, "## Summary") |
| 244 | fmt.Fprintln(&b) |
| 245 | fmt.Fprintln(&b, summary) |
| 246 | |
| 247 | if len(rest) == 0 { |
| 248 | return summary, tags, b.String() |
| 249 | } |
| 250 | |
| 251 | grouped := groupByKind(rest) |
| 252 | for _, kind := range []string{KindFact, KindDecision, KindPreference} { |
| 253 | entries := grouped[kind] |
| 254 | if len(entries) == 0 { |
| 255 | continue |
| 256 | } |
| 257 | fmt.Fprintf(&b, "\n## %s\n\n", titleCase(kind+"s")) |
| 258 | for _, e := range entries { |
| 259 | fmt.Fprintf(&b, "- %s\n", e.Content) |
| 260 | } |
| 261 | delete(grouped, kind) |
| 262 | } |
| 263 | // Anything with a custom or empty Kind falls under Notes so it's still |
| 264 | // preserved in the file even if it doesn't match the canonical kinds. |
| 265 | var extras []Entry |
| 266 | for _, es := range grouped { |
| 267 | extras = append(extras, es...) |
| 268 | } |
| 269 | if len(extras) > 0 { |
| 270 | fmt.Fprintln(&b, "\n## Notes") |
| 271 | fmt.Fprintln(&b) |
| 272 | for _, e := range extras { |
| 273 | if e.Kind != "" { |
| 274 | fmt.Fprintf(&b, "- (%s) %s\n", e.Kind, e.Content) |
| 275 | } else { |
| 276 | fmt.Fprintf(&b, "- %s\n", e.Content) |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | return summary, tags, b.String() |
| 281 | } |
| 282 |
no test coverage detected