|
| 1 | +import re |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +INDEX_PATH = Path("index.md") |
| 5 | +ARCHIVE_PATH = Path("archive.md") |
| 6 | + |
| 7 | + |
| 8 | +def extract_recent_from_archive(limit=5): |
| 9 | + """Grab the most recent devlog lines from archive.md (assumes newest first).""" |
| 10 | + if not ARCHIVE_PATH.exists(): |
| 11 | + return [] |
| 12 | + lines = ARCHIVE_PATH.read_text(encoding="utf-8").splitlines() |
| 13 | + entries = [ln for ln in lines if ln.strip().startswith("- [")] |
| 14 | + return entries[:limit] |
| 15 | + |
| 16 | + |
| 17 | +def replace_recent_block(index_text, new_lines): |
| 18 | + start = "<!-- DEVLOG-RECENT-START -->" |
| 19 | + end = "<!-- DEVLOG-RECENT-END -->" |
| 20 | + if start not in index_text or end not in index_text: |
| 21 | + # If markers are missing, leave unchanged |
| 22 | + return index_text |
| 23 | + pattern = re.compile( |
| 24 | + rf"{re.escape(start)}.*?{re.escape(end)}", |
| 25 | + flags=re.DOTALL, |
| 26 | + ) |
| 27 | + block = "\n".join([start] + new_lines + [end]) |
| 28 | + return pattern.sub(block, index_text) |
| 29 | + |
| 30 | + |
| 31 | +def main(): |
| 32 | + recent = extract_recent_from_archive() |
| 33 | + if not recent: |
| 34 | + return |
| 35 | + index_text = INDEX_PATH.read_text(encoding="utf-8") |
| 36 | + updated = replace_recent_block(index_text, recent) |
| 37 | + if updated != index_text: |
| 38 | + INDEX_PATH.write_text(updated, encoding="utf-8") |
| 39 | + print("Updated Recent Devlog Entries in index.md") |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + main() |
| 44 | + |
0 commit comments