unfolding by only 1 depth.
This commit is contained in:
parent
9999e5a3a8
commit
383849d4f2
3 changed files with 96 additions and 3 deletions
|
|
@ -84,6 +84,11 @@ def build_argparser():
|
|||
help="Append index.html to menu items to aid navigation",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument(
|
||||
'--unfolding',
|
||||
help="Enable unfolding detecting .unfolding",
|
||||
action="store_true")
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,90 @@ def write_index(args,index, html, html_head, html_footer):
|
|||
f.write(html_footer)
|
||||
|
||||
|
||||
def render_dir(args, root):
|
||||
html = []
|
||||
|
||||
for entry in os.listdir(root):
|
||||
|
||||
if args.no_hidden:
|
||||
if entry.startswith('.'):
|
||||
continue
|
||||
|
||||
name = entry
|
||||
lv = root.split("/")
|
||||
relative = lv[len(lv) - 1]
|
||||
relative_path = "./{}/{}".format(relative, name)
|
||||
|
||||
if os.path.isfile(root + '/' + entry):
|
||||
|
||||
if 'index.html' not in name:
|
||||
full_path = os.path.join(root, name)
|
||||
mime = MIME_TYPE.from_file(full_path)
|
||||
# example: MIME plain/text becomes 'type' plain 'subtype' text
|
||||
type_, subtype = mime.split('/')
|
||||
|
||||
caption = name
|
||||
|
||||
if args.verbose:
|
||||
print('Found file in dir ', name, 'as', mime)
|
||||
|
||||
if type_ in FILE_TYPES:
|
||||
a = FILE_TYPES[type_].format(relative_path, caption)
|
||||
|
||||
# expansion for different kind of text files
|
||||
if type_ == 'text':
|
||||
if name.endswith('.html') or subtype == 'html':
|
||||
subtype = 'html'
|
||||
# what types of text files to expand
|
||||
a = '<section id="{}">{}</section>'.format(name, open(full_path).read())
|
||||
elif subtype in CODE_TYPES or name.endswith('.txt'):
|
||||
# if the plain text is code,
|
||||
# which types do we wrap in pre-tags?
|
||||
a = "<div>" + open(full_path).read() + "</div>"
|
||||
else:
|
||||
subtype = subtype + ' unkown-file'
|
||||
a = "<a href='{}'>{}</a>"
|
||||
# a = FILE_TYPES[type_]
|
||||
|
||||
if type_ == 'image':
|
||||
a = FILE_TYPES[type_].format(relative_path, caption)
|
||||
if args.thumbnail:
|
||||
a = thumbnail(relative_path, relative_path, args)
|
||||
if args.no_filenames:
|
||||
caption = ""
|
||||
if args.captions:
|
||||
caption = caption(relative_path)
|
||||
a = FILE_TYPES[type_].format(relative_path, caption)
|
||||
|
||||
if subtype in SUB_TYPES:
|
||||
a = SUB_TYPES[subtype]
|
||||
|
||||
if type_ not in FILE_TYPES and subtype not in SUB_TYPES:
|
||||
# catch exceptions not yet defined in FILE_TYPES or SUB_TYPES
|
||||
a = "<a href='{}'>{}</a>"
|
||||
if args.verbose:
|
||||
message = 'not in list of file types, adding as plain href: \n'
|
||||
print(type_, subtype, message, name)
|
||||
subtype = subtype + ' unkown-file'
|
||||
|
||||
a = a.replace('{}', relative_path)
|
||||
html.append(div(args, type_, subtype, a, name))
|
||||
|
||||
if os.path.isdir(root + '/' + entry):
|
||||
|
||||
if args.menu_with_index:
|
||||
a = "<a href='{}/index.html'>{}</a>".replace('{}', relative_path)
|
||||
else:
|
||||
a = "<a href='{}'>{}/</a>".replace('{}', relative_path)
|
||||
html.append(div(args, 'dir', 'dir', a, 'folder'))
|
||||
# html.insert(0, div(args, 'dir', 'dir', a, 'folder'))
|
||||
|
||||
result = ""
|
||||
for line in html:
|
||||
result += line + "\n"
|
||||
return result
|
||||
|
||||
|
||||
def distribusify(args, directory): # noqa
|
||||
for root, dirs, files in os.walk(directory):
|
||||
|
||||
|
|
@ -196,8 +280,12 @@ def distribusify(args, directory): # noqa
|
|||
a = "<a href='{}/index.html'>{}</a>".replace('{}', name)
|
||||
else:
|
||||
a = "<a href='{}'>{}/</a>".replace('{}', name)
|
||||
|
||||
html.insert(0, div(args, 'dir', 'dir', a, 'folder'))
|
||||
if args.unfolding:
|
||||
rd = render_dir(args, "{}/{}".format(root, name))
|
||||
h = '<div id="folder-{}" class="unfolded">\n{}\n{}</div>'.format(name, a, rd)
|
||||
html.append(h)
|
||||
else:
|
||||
html.insert(0, div(args, 'dir', 'dir', a, 'folder'))
|
||||
|
||||
index = os.path.join(root, 'index.html')
|
||||
if os.path.exists(index):
|
||||
|
|
|
|||
2
run.sh
2
run.sh
|
|
@ -1,4 +1,4 @@
|
|||
#!/bin/bash
|
||||
|
||||
pip install -r py3/requirements.txt
|
||||
python run.py -d ./data/ -nf -s custom.css --no-hidden -v
|
||||
python run.py -d ./data/ -nf -s custom.css --no-hidden --unfolding
|
||||
|
|
|
|||
Loading…
Reference in a new issue