fix: add parent tags to folders_to_tags macro and start tagging at root folder (#940)

* start tagging from root and add parent tags

* update snapshot to pass test
This commit is contained in:
rsazra
2025-06-04 04:22:17 -04:00
committed by GitHub
parent e1117bf1a1
commit e4bb07e852
2 changed files with 6 additions and 6 deletions

View File

@@ -44,14 +44,14 @@ class BranchData:
def add_folders_to_tree(library: Library, tree: BranchData, items: tuple[str, ...]) -> BranchData:
branch = tree
parent_tag = None
for folder in items:
if folder not in branch.dirs:
# TODO: Reimplement parent tags
new_tag = Tag(name=folder)
new_tag = Tag(name=folder, parent_tags=({parent_tag} if parent_tag else None))
library.add_tag(new_tag)
branch.dirs[folder] = BranchData(tag=new_tag)
branch.tag = new_tag
branch = branch.dirs[folder]
parent_tag = branch.tag
return branch
@@ -71,7 +71,7 @@ def folders_to_tags(library: Library):
add_tag_to_tree(reversed_tag)
for entry in library.get_entries():
folders = entry.path.parts[1:-1]
folders = entry.path.parts[0:-1]
if not folders:
continue
@@ -124,7 +124,7 @@ def generate_preview_data(library: Library) -> BranchData:
add_tag_to_tree(reversed_tag)
for entry in library.get_entries():
folders = entry.path.parts[1:-1]
folders = entry.path.parts[0:-1]
if not folders:
continue

View File

@@ -1,4 +1,4 @@
# serializer version: 1
# name: test_generate_preview_data
BranchData(dirs={'two': BranchData(dirs={}, files=['bar.md'], tag=<Tag ID: None Name: two>)}, files=[], tag=None)
BranchData(dirs={'one': BranchData(dirs={'two': BranchData(dirs={}, files=['bar.md'], tag=<Tag ID: None Name: two>)}, files=[], tag=<Tag ID: None Name: one>)}, files=[], tag=None)
# ---