INNER CODE UNIT · Python
parse_frontmatter
zhinkgit/embeddedskills · .github/maintenance/repo_checks.py:31
def parse_frontmatter(path: Path) -> dict[str, str]:
text = path.read_text(encoding="utf-8")
match = FRONTMATTER_PATTERN.match(text)
if not match:
raise ValueError("missing frontmatter enclosed by ---")
values: dict[str, str] = {}
block_key: str | None = None
for line in match.group(1).splitlines():
if line[:1].isspace() and block_key:
continuation = line.strip()
if continuation:
values[block_key] = " ".join(
part for part in (values[block_key], continuation) if part
)
continue
block_key = None