ingestion: strip repeated front-matter blocks from notes
This commit is contained in:
@@ -692,14 +692,26 @@ def _make_document(**values) -> loader.Document:
|
|||||||
|
|
||||||
|
|
||||||
def _strip_front_matter(text: str) -> str:
|
def _strip_front_matter(text: str) -> str:
|
||||||
"""Drop a leading YAML block. The Note path parses it; files only need it gone."""
|
"""Drop leading YAML blocks. The Note path parses them; files only need them gone.
|
||||||
lines = text.splitlines()
|
|
||||||
if not lines or lines[0].strip() != "---":
|
Some notes carry two blocks in a row (a stale export, or a block followed by
|
||||||
return text
|
a horizontal rule that closes), so this repeats. It never strips a body that
|
||||||
for index in range(1, len(lines)):
|
does not have a closing delimiter.
|
||||||
if lines[index].strip() in ("---", "..."):
|
"""
|
||||||
return "\n".join(lines[index + 1 :]).strip()
|
body = text
|
||||||
return text
|
for _ in range(3):
|
||||||
|
lines = body.splitlines()
|
||||||
|
if not lines or lines[0].strip() != "---":
|
||||||
|
return body
|
||||||
|
closing = None
|
||||||
|
for index in range(1, len(lines)):
|
||||||
|
if lines[index].strip() in ("---", "..."):
|
||||||
|
closing = index
|
||||||
|
break
|
||||||
|
if closing is None:
|
||||||
|
return body
|
||||||
|
body = "\n".join(lines[closing + 1 :]).strip()
|
||||||
|
return body
|
||||||
|
|
||||||
|
|
||||||
def _split_note(text: str, validator) -> tuple:
|
def _split_note(text: str, validator) -> tuple:
|
||||||
@@ -724,7 +736,9 @@ def _split_note(text: str, validator) -> tuple:
|
|||||||
fields = parsed
|
fields = parsed
|
||||||
except validator.YamlError:
|
except validator.YamlError:
|
||||||
fields = {}
|
fields = {}
|
||||||
return fields, "\n".join(lines[end + 1 :]).strip()
|
# Strip any further leading block as well, so a duplicate front-matter block
|
||||||
|
# never reaches the chunker.
|
||||||
|
return fields, _strip_front_matter("\n".join(lines[end + 1 :]).strip())
|
||||||
|
|
||||||
|
|
||||||
def _source_row(name: str, enabled: bool, documents: list, extra: dict = None) -> dict:
|
def _source_row(name: str, enabled: bool, documents: list, extra: dict = None) -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user