(path: Path)
| 193 | |
| 194 | |
| 195 | def parse_post(path: Path) -> Post | None: |
| 196 | text = path.read_text(encoding="utf-8") |
| 197 | try: |
| 198 | fm, body = parse_front_matter(text) |
| 199 | except ValueError: |
| 200 | return None |
| 201 | date_value = fm.get("date") |
| 202 | if not isinstance(date_value, str): |
| 203 | return None |
| 204 | try: |
| 205 | date = dt.date.fromisoformat(date_value[:10]) |
| 206 | except ValueError: |
| 207 | return None |
| 208 | slug = fm.get("slug") or path.stem |
| 209 | title = fm.get("title") or slug |
| 210 | return Post(path=path, slug=slug, title=str(title), date=date, front_matter=fm, body=body) |
| 211 | |
| 212 | |
| 213 | def discover_posts(blog_dir: Path) -> list[Post]: |
no test coverage detected