24 lines
484 B
Python
24 lines
484 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import tomlkit
|
|
|
|
Frontmatter = dict[str, Any]
|
|
|
|
|
|
def load_frontmatter(s: str) -> dict[str, Any] | None:
|
|
"""Load frontmatter from the contents of an example README.md."""
|
|
start = s.find("<!--[metadata]")
|
|
if start == -1:
|
|
return None
|
|
start += len("<!--[metadata]")
|
|
|
|
end = s.find("-->", start)
|
|
if end == -1:
|
|
return None
|
|
|
|
fm = s[start:end].strip()
|
|
|
|
return tomlkit.loads(fm).unwrap()
|