fix: preserve document hierarchy in vault during pull
All checks were successful
Deploy / deploy (push) Successful in 11s

New documents now placed in parent's subdirectory (coll/Parent/Child.md)
instead of flat in the collection dir. Parent paths registered immediately
so nested children resolve correctly within the same pull.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-03-08 12:27:38 +01:00
parent 8c95bb141f
commit 2a4d15fd94

View File

@@ -434,13 +434,18 @@ class OutlineSync:
print(f"ok: {rel} updated")
updated += 1
else:
# New document — determine path from collection/title
# New document — determine path from collection + parent hierarchy
safe_coll = sanitize_name(
next((c["name"] for c in collections if c["id"] == coll_id), coll_id)
)
coll_dir = self.vault_dir / safe_coll
coll_dir.mkdir(parents=True, exist_ok=True)
path = self._unique_path(coll_dir, sanitize_name(title))
if parent_id and parent_id in vault_ids:
parent_path = vault_ids[parent_id]
target_dir = parent_path.parent / parent_path.stem
else:
target_dir = coll_dir
target_dir.mkdir(parents=True, exist_ok=True)
path = self._unique_path(target_dir, sanitize_name(title))
fm = {
"outline_id": doc_id,
"outline_collection_id": coll_id,
@@ -449,6 +454,7 @@ class OutlineSync:
}
content = build_frontmatter(fm) + "\n" + full.get("text", "")
path.write_text(content, encoding="utf-8")
vault_ids[doc_id] = path # register so child docs resolve parent correctly
rel = str(path.relative_to(self.vault_dir))
print(f"ok: {rel} created")
created += 1