mobile friendliness
This commit is contained in:
74
py-packages/SimpleWebPage/simplewebpage/__init__.py
Executable file → Normal file
74
py-packages/SimpleWebPage/simplewebpage/__init__.py
Executable file → Normal file
@@ -14,8 +14,10 @@ from glob import fnmatch
|
|||||||
import base64
|
import base64
|
||||||
import random
|
import random
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import markdown
|
import markdown
|
||||||
|
|
||||||
MARKDOWN_AVAILABLE = True
|
MARKDOWN_AVAILABLE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
MARKDOWN_AVAILABLE = False
|
MARKDOWN_AVAILABLE = False
|
||||||
@@ -33,19 +35,20 @@ SAFE_OPTS = (
|
|||||||
"media",
|
"media",
|
||||||
"includes",
|
"includes",
|
||||||
"no_readme",
|
"no_readme",
|
||||||
"reverse"
|
"reverse",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
""" Setup the command line options """
|
"""Setup the command line options"""
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
parser = ArgumentParser(
|
parser = ArgumentParser(
|
||||||
epilog="Recursively generate indexes: \n# find . -type d -not -path '*/.*' -exec SimpleWebPage \{\} \;"
|
epilog="Recursively generate indexes: \n# find . -type d -not -path '*/.*' -exec SimpleWebPage \{\} \;"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-f","--force",
|
"-f",
|
||||||
|
"--force",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
dest="overwrite",
|
dest="overwrite",
|
||||||
default=False,
|
default=False,
|
||||||
@@ -105,7 +108,7 @@ def setup():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
dest="reverse",
|
dest="reverse",
|
||||||
default=False,
|
default=False,
|
||||||
help="Reverse sort"
|
help="Reverse sort",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--images",
|
"--images",
|
||||||
@@ -166,7 +169,7 @@ def setup2JSON(opts):
|
|||||||
|
|
||||||
|
|
||||||
def HTML2setup(opts, overwrite):
|
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:
|
try:
|
||||||
read_config = False
|
read_config = False
|
||||||
@@ -238,8 +241,8 @@ def generate_index(opts):
|
|||||||
files = [f for f in files if f != opts.password_filename]
|
files = [f for f in files if f != opts.password_filename]
|
||||||
files = match_files(files, opts.includes)
|
files = match_files(files, opts.includes)
|
||||||
dirs = match_files(dirs, opts.includes)
|
dirs = match_files(dirs, opts.includes)
|
||||||
dirs.sort(reverse = opts.reverse)
|
dirs.sort(reverse=opts.reverse)
|
||||||
files.sort(reverse = opts.reverse)
|
files.sort(reverse=opts.reverse)
|
||||||
files.sort(key=lambda x: x.find("/") > 0)
|
files.sort(key=lambda x: x.find("/") > 0)
|
||||||
readme = get_readme(path, opts.no_readme)
|
readme = get_readme(path, opts.no_readme)
|
||||||
with open(os.path.join(path, opts.filename), "wt") as f:
|
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)))
|
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
|
||||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||||
fname_str = fname
|
fname_str = fname
|
||||||
|
fname_media = ""
|
||||||
if images and is_imagefile(fname):
|
if images and is_imagefile(fname):
|
||||||
fname_str = get_imagestr(fname)
|
fname_media = get_imagestr(fname)
|
||||||
if media and is_audiofile(fname):
|
if media and is_audiofile(fname):
|
||||||
fname_str = get_audiostr(fname)
|
fname_media = get_audiostr(fname)
|
||||||
if media and is_videofile(fname):
|
if media and is_videofile(fname):
|
||||||
fname_str = get_videostr(fname)
|
fname_media = get_videostr(fname)
|
||||||
return (
|
return (
|
||||||
'<tr class="row_file"><td><a class="link_file" href="%s"> %s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
|
'<tr class="row_file"><td><a class="link_file" href="%s"> %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, fsstr, fsstrb, fdstr)
|
% (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):
|
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):
|
def get_audiostr(fname):
|
||||||
return '%s<br><audio src="%s" controls class=audio></audio>' % (
|
return '<br><audio src="%s" controls class=audio></audio>' % (
|
||||||
fname,
|
|
||||||
urllib.parse.quote(fname),
|
urllib.parse.quote(fname),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_videostr(fname):
|
def get_videostr(fname):
|
||||||
return '%s<br><video class=video controls><source src="%s"></video>' % (
|
return '<br><video class=video controls><source src="%s"></video>' % (
|
||||||
fname,
|
|
||||||
urllib.parse.quote(fname),
|
urllib.parse.quote(fname),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -475,15 +480,12 @@ def get_readme(path, no_read):
|
|||||||
|
|
||||||
if no_read:
|
if no_read:
|
||||||
return ""
|
return ""
|
||||||
if not os.path.exists(os.path.join(path,"README.md")):
|
if not os.path.exists(os.path.join(path, "README.md")):
|
||||||
return ""
|
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:
|
if MARKDOWN_AVAILABLE:
|
||||||
return "<div class=readme>{}</div>".format(
|
return "<div class=readme>{}</div>".format(
|
||||||
markdown.markdown(
|
markdown.markdown(fp.read().strip(), extensions=["extra"])
|
||||||
fp.read().strip(),
|
|
||||||
extensions=['extra']
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -911,8 +913,12 @@ function alternate(table) {
|
|||||||
.bytes {
|
.bytes {
|
||||||
font-size: xx-small;
|
font-size: xx-small;
|
||||||
}
|
}
|
||||||
|
.image {
|
||||||
|
max-width: 90%;
|
||||||
|
}
|
||||||
.audio {
|
.audio {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
|
padding-left: 5px;
|
||||||
}
|
}
|
||||||
.video {
|
.video {
|
||||||
width: 320;
|
width: 320;
|
||||||
@@ -928,6 +934,26 @@ function alternate(table) {
|
|||||||
.readme code {
|
.readme code {
|
||||||
color: #0060EB;
|
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>
|
</style>
|
||||||
"""
|
"""
|
||||||
header = (
|
header = (
|
||||||
@@ -1006,9 +1032,11 @@ def sizeof(num):
|
|||||||
return "%3.1f %s" % (num, x)
|
return "%3.1f %s" % (num, x)
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
opts = setup()
|
opts = setup()
|
||||||
generate_index(opts)
|
generate_index(opts)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user