fix: preserve document hierarchy in vault during pull
All checks were successful
Deploy / deploy (push) Successful in 11s
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:
@@ -434,13 +434,18 @@ class OutlineSync:
|
|||||||
print(f"ok: {rel} updated")
|
print(f"ok: {rel} updated")
|
||||||
updated += 1
|
updated += 1
|
||||||
else:
|
else:
|
||||||
# New document — determine path from collection/title
|
# New document — determine path from collection + parent hierarchy
|
||||||
safe_coll = sanitize_name(
|
safe_coll = sanitize_name(
|
||||||
next((c["name"] for c in collections if c["id"] == coll_id), coll_id)
|
next((c["name"] for c in collections if c["id"] == coll_id), coll_id)
|
||||||
)
|
)
|
||||||
coll_dir = self.vault_dir / safe_coll
|
coll_dir = self.vault_dir / safe_coll
|
||||||
coll_dir.mkdir(parents=True, exist_ok=True)
|
if parent_id and parent_id in vault_ids:
|
||||||
path = self._unique_path(coll_dir, sanitize_name(title))
|
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 = {
|
fm = {
|
||||||
"outline_id": doc_id,
|
"outline_id": doc_id,
|
||||||
"outline_collection_id": coll_id,
|
"outline_collection_id": coll_id,
|
||||||
@@ -449,6 +454,7 @@ class OutlineSync:
|
|||||||
}
|
}
|
||||||
content = build_frontmatter(fm) + "\n" + full.get("text", "")
|
content = build_frontmatter(fm) + "\n" + full.get("text", "")
|
||||||
path.write_text(content, encoding="utf-8")
|
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))
|
rel = str(path.relative_to(self.vault_dir))
|
||||||
print(f"ok: {rel} created")
|
print(f"ok: {rel} created")
|
||||||
created += 1
|
created += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user