Skip to content

Commit

Permalink
Recursively sort piggymap
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Aug 25, 2024
1 parent 3cdb3bc commit c3d3fd3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions piggy/piggybank.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ def generate_piggymap(path: Path, max_levels: int = 5, _current_level: int = 0):
"heading": sections["heading"],
"meta": sections["meta"],
}
return piggymap

def recursive_sort(data):
for key, value in data.items():
if isinstance(value, dict):
data[key] = recursive_sort(value)
return dict(sorted(data.items()))

return recursive_sort(piggymap)

PIGGYMAP = generate_piggymap(PIGGYBANK_FOLDER)

# Sort everything in the piggymap alphabetically
for key, value in PIGGYMAP.items():
if isinstance(value, dict):
PIGGYMAP[key] = dict(sorted(value.items()))
PIGGYMAP = dict(sorted(PIGGYMAP.items()))
PIGGYMAP = generate_piggymap(PIGGYBANK_FOLDER)

0 comments on commit c3d3fd3

Please sign in to comment.