mobile friendliness

This commit is contained in:
Q
2021-11-15 09:00:16 +02:00
parent 69538eb628
commit e6cf518e33

76
py-packages/SimpleWebPage/simplewebpage/__init__.py Executable file → Normal file
View File

@@ -14,8 +14,10 @@ from glob import fnmatch
import base64
import random
from pprint import pprint
try:
import markdown
MARKDOWN_AVAILABLE = True
except ImportError:
MARKDOWN_AVAILABLE = False
@@ -33,19 +35,20 @@ SAFE_OPTS = (
"media",
"includes",
"no_readme",
"reverse"
"reverse",
)
def setup():
""" Setup the command line options """
"""Setup the command line options"""
from argparse import ArgumentParser
parser = ArgumentParser(
epilog="Recursively generate indexes: \n# find . -type d -not -path '*/.*' -exec SimpleWebPage \{\} \;"
)
parser.add_argument(
"-f","--force",
"-f",
"--force",
action="store_true",
dest="overwrite",
default=False,
@@ -105,7 +108,7 @@ def setup():
action="store_true",
dest="reverse",
default=False,
help="Reverse sort"
help="Reverse sort",
)
parser.add_argument(
"--images",
@@ -166,7 +169,7 @@ def setup2JSON(opts):
def HTML2setup(opts, overwrite):
""" returns new opts and was it able to read HTML, if overwriting, do not update config """
"""returns new opts and was it able to read HTML, if overwriting, do not update config"""
try:
read_config = False
@@ -178,7 +181,7 @@ def HTML2setup(opts, overwrite):
for key in config:
if key in SAFE_OPTS:
if not overwrite:
setattr(opts, key, config[key])
setattr(opts, key, config[key])
read_config = True
if not overwrite:
print("Read options from existing " + opts.filename)
@@ -238,8 +241,8 @@ def generate_index(opts):
files = [f for f in files if f != opts.password_filename]
files = match_files(files, opts.includes)
dirs = match_files(dirs, opts.includes)
dirs.sort(reverse = opts.reverse)
files.sort(reverse = opts.reverse)
dirs.sort(reverse=opts.reverse)
files.sort(reverse=opts.reverse)
files.sort(key=lambda x: x.find("/") > 0)
readme = get_readme(path, opts.no_readme)
with open(os.path.join(path, opts.filename), "wt") as f:
@@ -303,15 +306,16 @@ def get_filelink(path, fname, images=False, media=False):
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
fname_str = fname
fname_media = ""
if images and is_imagefile(fname):
fname_str = get_imagestr(fname)
fname_media = get_imagestr(fname)
if media and is_audiofile(fname):
fname_str = get_audiostr(fname)
fname_media = get_audiostr(fname)
if media and is_videofile(fname):
fname_str = get_videostr(fname)
fname_media = get_videostr(fname)
return (
'<tr class="row_file"><td><a class="link_file" href="%s">&nbsp;&nbsp;%s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
% (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr)
'<tr class="row_file"><td><a class="link_file" href="%s">&nbsp;&nbsp;%s</a>%s<td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
% (urllib.parse.quote(fname), fname_str, fname_media, fsstr, fsstrb, fdstr)
)
@@ -327,19 +331,20 @@ def get_download_lines(files, recursive=False):
def get_imagestr(fname):
return '<img src="%s" title="%s"/>' % (urllib.parse.quote(fname), fname)
return '<br><img class=image src="%s" title="%s"/>' % (
urllib.parse.quote(fname),
fname,
)
def get_audiostr(fname):
return '%s<br><audio src="%s" controls class=audio></audio>' % (
fname,
return '<br><audio src="%s" controls class=audio></audio>' % (
urllib.parse.quote(fname),
)
def get_videostr(fname):
return '%s<br><video class=video controls><source src="%s"></video>' % (
fname,
return '<br><video class=video controls><source src="%s"></video>' % (
urllib.parse.quote(fname),
)
@@ -475,15 +480,12 @@ def get_readme(path, no_read):
if no_read:
return ""
if not os.path.exists(os.path.join(path,"README.md")):
if not os.path.exists(os.path.join(path, "README.md")):
return ""
with open(os.path.join(path,"README.md"), "rt") as fp:
with open(os.path.join(path, "README.md"), "rt") as fp:
if MARKDOWN_AVAILABLE:
return "<div class=readme>{}</div>".format(
markdown.markdown(
fp.read().strip(),
extensions=['extra']
)
markdown.markdown(fp.read().strip(), extensions=["extra"])
)
else:
@@ -911,8 +913,12 @@ function alternate(table) {
.bytes {
font-size: xx-small;
}
.image {
max-width: 90%;
}
.audio {
width: 90%;
padding-left: 5px;
}
.video {
width: 320;
@@ -928,6 +934,26 @@ function alternate(table) {
.readme code {
color: #0060EB;
}
@media only screen and (max-width: 600px) {
.container {
margin: 0;
min-width: 800px;
display: block;
}
table {
margin: 0;
width: 800px;
}
td {
padding-top: 10px;
padding-bottom: 10px;
max-width: 400px;
}
td a {
max-width: 400px;
word-break: break-all;
}
}
</style>
"""
header = (
@@ -1006,9 +1032,11 @@ def sizeof(num):
return "%3.1f&nbsp;%s" % (num, x)
num /= 1024.0
def main():
opts = setup()
generate_index(opts)
if __name__ == "__main__":
main()