refactoring
This commit is contained in:
parent
eec6016737
commit
e93a3e3b28
@ -100,19 +100,12 @@ def check_distribusi_index(args, index):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def write_index(args, index, html):
|
def write_index_html(args, index, html):
|
||||||
with open(index, "w") as index_file:
|
with open(index, "w") as index_file:
|
||||||
if args.style:
|
styled_html_head = html_head.format(cssfile=args.style)
|
||||||
file_style = open(args.style, "r")
|
|
||||||
style = file_style.read()
|
|
||||||
styled_html_head = html_head % style
|
|
||||||
else:
|
|
||||||
styled_html_head = html_head % ""
|
|
||||||
index_file.write(styled_html_head)
|
index_file.write(styled_html_head)
|
||||||
|
|
||||||
for line in html:
|
for line in html:
|
||||||
index_file.write(line + "\n")
|
index_file.write(line + "\n")
|
||||||
|
|
||||||
index_file.write(html_footer)
|
index_file.write(html_footer)
|
||||||
|
|
||||||
|
|
||||||
@ -187,6 +180,23 @@ def remove_hidden_files_and_folders(dirs, files):
|
|||||||
return dirs, files
|
return dirs, files
|
||||||
|
|
||||||
|
|
||||||
|
def is_skipped_file(name, args):
|
||||||
|
if "index.html" in name:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if name.endswith("_thumbnail.jpg"):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if name.endswith("_alttext.txt"):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if name.endswith("_dv_description.txt"):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if args.style in name:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def distribusify(args, directory): # noqa
|
def distribusify(args, directory): # noqa
|
||||||
for root, dirs, files in os.walk(directory):
|
for root, dirs, files in os.walk(directory):
|
||||||
html = []
|
html = []
|
||||||
@ -208,16 +218,7 @@ def distribusify(args, directory): # noqa
|
|||||||
print("Generating directory listing for", root)
|
print("Generating directory listing for", root)
|
||||||
|
|
||||||
for name in sorted(files):
|
for name in sorted(files):
|
||||||
if "index.html" in name:
|
if is_skipped_file(name, args):
|
||||||
continue
|
|
||||||
|
|
||||||
if name.endswith("_thumbnail.jpg"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if name.endswith("_alttext.txt"):
|
|
||||||
continue
|
|
||||||
|
|
||||||
if name.endswith("_dv_description.txt"):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
full_path = os.path.join(root, name)
|
full_path = os.path.join(root, name)
|
||||||
@ -271,8 +272,4 @@ def distribusify(args, directory): # noqa
|
|||||||
html.insert(0, format_div(args, "dir", "dir", tag, "folder"))
|
html.insert(0, format_div(args, "dir", "dir", tag, "folder"))
|
||||||
|
|
||||||
index = os.path.join(root, "index.html")
|
index = os.path.join(root, "index.html")
|
||||||
if os.path.exists(index):
|
write_index_html(args, index, html)
|
||||||
if check_distribusi_index(args, index):
|
|
||||||
write_index(args, index, html)
|
|
||||||
elif not os.path.exists(index):
|
|
||||||
write_index(args, index, html)
|
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
html_head = """
|
html_head = '''\
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/distribusi -->
|
<!-- Generated with distribusi https://git.vvvvvvaria.org/crunk/distribusi -->
|
||||||
<meta name="generator" content="distribusi" />
|
<meta name="generator" content="distribusi" />
|
||||||
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
||||||
<style>
|
<link rel="stylesheet" href="{cssfile}" crossorigin="anonymous">
|
||||||
.image{max-width: 100%%;}
|
|
||||||
.pdf object{width:640px;height: 640px;}
|
|
||||||
.dir::before{content:"📁 ";font-size:18px;}
|
|
||||||
.filename{display:block;font-family:mono;}
|
|
||||||
.unkown-file::before{content:"📄 ";font-size:18px;}
|
|
||||||
div{max-width: 640px;display:inline-block;vertical-align:top;margin:1em;padding:1em;}
|
|
||||||
video {width:640px;max-height:640px;}
|
|
||||||
%s
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
"""
|
'''
|
||||||
|
|
||||||
html_footer = """
|
html_footer ='''\
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
'''
|
||||||
|
Loading…
Reference in New Issue
Block a user