CoolFace
Apppublic

shj7972/bootstrap

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
utils.py23 linesDownload Raw Back to rag
1from pathlib import Path2import re3 4 5META_RE = re.compile(r"^---\s*(.*?)\s*---\s*(.*)$", re.S)6 7 8def load_docs(dirpath: str):9    items = []10    for p in Path(dirpath).glob("*.md"):11        txt = p.read_text(encoding="utf-8")12        m = META_RE.match(txt)13        if m:14            meta_raw, body = m.groups()15            meta = {}16            for line in meta_raw.splitlines():17                if ":" in line:18                    k, v = line.split(":", 1)19                    meta[k.strip()] = v.strip()20        else:21            meta, body = {}, txt22        items.append({"path": str(p), "meta": meta, "text": body.strip()})23    return items