From 2a4d15fd94c0f1d175fa8be21ff7d491a6297817 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 8 Mar 2026 12:27:38 +0100 Subject: [PATCH] fix: preserve document hierarchy in vault during pull 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 --- outline_sync.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/outline_sync.py b/outline_sync.py index 0f438a3..d12a4f3 100644 --- a/outline_sync.py +++ b/outline_sync.py @@ -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