ingestion: strip front-matter from harvested markdown

This commit is contained in:
Paperclip Builder
2026-10-26 22:32:14 +11:00
parent da674b5555
commit 4896e18a41

View File

@@ -284,7 +284,10 @@ def _file_document(result, client, guide, repo, branch, area, updated, created,
kind = "code" if exclusions.extension(path) not in ("md", "markdown", "mdx", "txt", "rst") else "markdown"
title = f"{full_name} — {path}"
body = text
body = _strip_front_matter(text) if kind == "markdown" else text
if not body.strip():
result.add_rejection(exclusions.Rejection(path, "gitea", "front-matter only", full_name))
return None
if description or topics:
header = [f"Repository: {full_name}"]
if description:
@@ -688,6 +691,17 @@ def _make_document(**values) -> loader.Document:
)
def _strip_front_matter(text: str) -> str:
"""Drop a leading YAML block. The Note path parses it; files only need it gone."""
lines = text.splitlines()
if not lines or lines[0].strip() != "---":
return text
for index in range(1, len(lines)):
if lines[index].strip() in ("---", "..."):
return "\n".join(lines[index + 1 :]).strip()
return text
def _split_note(text: str, validator) -> tuple:
"""Tolerant front-matter split. A note without front-matter is still a note."""
lines = text.splitlines()