(
content: str,
*,
user_profile: Optional[Dict[str, Any]] = None,
)
| 2569 | |
| 2570 | def _refresh_daily_note_topic_summaries( |
| 2571 | content: str, |
| 2572 | *, |
| 2573 | user_profile: Optional[Dict[str, Any]] = None, |
| 2574 | ) -> str: |
| 2575 | text = re.sub( |
| 2576 | r"\n?<!-- paperflow-topic-summary:start -->.*?<!-- paperflow-topic-summary:end -->\n?", |
| 2577 | "\n", |
| 2578 | str(content or ""), |
| 2579 | flags=re.DOTALL, |
| 2580 | ) |
| 2581 | matches = list(re.finditer(r"^#\s+(.+)$", text, flags=re.MULTILINE)) |
| 2582 | if not matches: |
| 2583 | return text |
| 2584 | pieces: List[str] = [] |
| 2585 | for index, match in enumerate(matches): |
| 2586 | start = match.start() |
| 2587 | body_start = match.end() |
| 2588 | end = matches[index + 1].start() if index + 1 < len(matches) else len(text) |
| 2589 | if index == 0: |
| 2590 | pieces.append(text[:body_start]) |
| 2591 | else: |
| 2592 | pieces.append(text[start:body_start]) |
| 2593 | category = match.group(1).strip() |
| 2594 | section_body = text[body_start:end] |
| 2595 | pieces.append("\n\n") |
| 2596 | pieces.append(_daily_note_topic_summary(category, section_body, user_profile=user_profile)) |
| 2597 | pieces.append("\n") |
| 2598 | pieces.append(section_body.strip("\n")) |
| 2599 | if index + 1 < len(matches): |
| 2600 | pieces.append("\n\n") |
| 2601 | return "\n".join(part.rstrip("\n") for part in pieces if part is not None).strip() + "\n" |
| 2602 | |
| 2603 | |
| 2604 | def _sync_obsidian_toc(daily_note: Path) -> None: |
| 2605 | year_dir = daily_note.parent |
no test coverage detected