Write summary page with frontmatter.
(
wiki_dir: Path, doc_name: str, summary: str, doc_type: str = "short", description: str = ""
)
| 916 | |
| 917 | |
| 918 | def _write_summary( |
| 919 | wiki_dir: Path, doc_name: str, summary: str, doc_type: str = "short", description: str = "" |
| 920 | ) -> None: |
| 921 | """Write summary page with frontmatter.""" |
| 922 | parts = frontmatter.split(summary) |
| 923 | if parts is not None: |
| 924 | _, summary = parts |
| 925 | summary = summary.lstrip("\n") |
| 926 | summaries_dir = wiki_dir / "summaries" |
| 927 | summaries_dir.mkdir(parents=True, exist_ok=True) |
| 928 | ext = "md" if doc_type == "short" else "json" |
| 929 | fm_lines = [_yaml_kv_line("type", "Summary")] |
| 930 | if description: |
| 931 | fm_lines.append(_yaml_kv_line("description", description)) |
| 932 | fm_lines.append(f"doc_type: {doc_type}") |
| 933 | fm_lines.append(_yaml_kv_line("full_text", f"sources/{doc_name}.{ext}")) |
| 934 | fm_block = "---\n" + "\n".join(fm_lines) + "\n---\n\n" |
| 935 | atomic_write_text(summaries_dir / f"{doc_name}.md", fm_block + summary) |
| 936 | |
| 937 | |
| 938 | _SAFE_NAME_RE = re.compile(r"[^\w\-]") |