do not show empty directories

This commit is contained in:
gurkenhabicht 2022-10-20 23:39:10 +02:00
parent 5d63accc32
commit 31c9ac2062
2 changed files with 40 additions and 3 deletions

View File

@ -6,7 +6,7 @@ from collections import deque
def sort_branch( lst ):
'''
sorts directories before files and
put directories in front of files and
sorts both alphabetically
'''
files = []
@ -36,12 +36,44 @@ def make_tree(path="templates/content"):
for name in lst:
fn = os.path.join(path, name)
if os.path.isdir(fn) and not fn.endswith(".git"):
tree['children'].append(make_tree(fn))
if os.listdir(fn): # this line is experimental and needs to be tested
tree['children'].append(make_tree(fn))
else:
if fn.endswith('.md') and not name == "README.md":
tree['children'].append(dict(name=fn))
return tree
#def clean_up_tree(tree):
# for key, val in tree.items():
# if isinstance(val, list):
# val = [ x for x in val if len(val) > 0]
# if isinstance(val, dict):
# clean_tree(tree)
# return tree
#def clean_up_tree(tree):
# '''
# create a clean directory structure inside the dict without empty lists
# '''
# import copy
# for key, val in tree.items():
# if isinstance(val, list):
# if len(val) < 1:
# del tree[key]
# else:
# for item in val:
# if isinstance(item, dict):
# clean_up_tree(item)
# return tree
#def clean_up_tree(tree):
# '''
# delete directories without content
# '''
# for key, val in tree.items():
# if isinstance(val, list) and len(val) == 0:
# del tree[key]
# return tree
def cut_path_tree(tree, subdir, file_ending):
'''
pruning of the tree structure from make_tree()

View File

@ -61,13 +61,18 @@ details summary::marker { content: "\1F4C1\20";}
.HolyGrail-nav li {
list-style-type: none!important;
padding-left : 0.5ch;
/* padding-left : 0.5ch; */
margin: 0em;
text-align: left;
/* experimental line height */
line-height: 1.5em;
list-style-position: inside;
}
.HolyGrail-nav li::marker {
content: "\1F4DD\20";
}
.HolyGrail-nav a{
overflow-wrap: break-word;
text-decoration: none;