simplewebage: include README.md
This commit is contained in:
@@ -14,11 +14,11 @@ import base64
|
|||||||
import random
|
import random
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
VERSION = "20210815"
|
VERSION = "20211002"
|
||||||
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
||||||
AUDIO_EXTENSIONS = ["wav", "mp3", "ogg"]
|
AUDIO_EXTENSIONS = ["wav", "mp3", "ogg"]
|
||||||
VIDEO_EXTENSIONS = ["mp4", "ogg", "webm"]
|
VIDEO_EXTENSIONS = ["mp4", "ogg", "webm"]
|
||||||
SAFE_OPTS = ("hidden","title","parent","recursive","images","media","includes")
|
SAFE_OPTS = ("hidden","title","parent","recursive","images","media","includes","no_readme")
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
""" Setup the command line options """
|
""" Setup the command line options """
|
||||||
@@ -41,6 +41,13 @@ def setup():
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show hidden files",
|
help="Show hidden files",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-readme",
|
||||||
|
action="store_true",
|
||||||
|
dest="no_readme",
|
||||||
|
default=False,
|
||||||
|
help="Do not show README.md on the page",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-t",
|
"-t",
|
||||||
type=str,
|
type=str,
|
||||||
@@ -90,7 +97,6 @@ def setup():
|
|||||||
default=False,
|
default=False,
|
||||||
help="Make media playable",
|
help="Make media playable",
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--include",
|
"--include",
|
||||||
"-i",
|
"-i",
|
||||||
@@ -207,6 +213,7 @@ def generate_index(opts):
|
|||||||
dirs.sort()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
files.sort(key=lambda x: x.find("/") > 0)
|
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:
|
with open(os.path.join(path, opts.filename), "wt") as f:
|
||||||
f.write(get_header(opts))
|
f.write(get_header(opts))
|
||||||
if opts.parent:
|
if opts.parent:
|
||||||
@@ -215,7 +222,7 @@ def generate_index(opts):
|
|||||||
f.write(get_pathlink(path, di))
|
f.write(get_pathlink(path, di))
|
||||||
for fi in files:
|
for fi in files:
|
||||||
f.write(get_filelink(path, fi, opts.images, opts.media))
|
f.write(get_filelink(path, fi, opts.images, opts.media))
|
||||||
f.write(get_footer())
|
f.write(get_footer(readme))
|
||||||
f.write(get_download_lines(files, recursive = opts.recursive))
|
f.write(get_download_lines(files, recursive = opts.recursive))
|
||||||
f.close()
|
f.close()
|
||||||
return
|
return
|
||||||
@@ -435,6 +442,14 @@ iframe {
|
|||||||
.replace("SECRET", secret, 1)
|
.replace("SECRET", secret, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_readme(path, no_read):
|
||||||
|
|
||||||
|
if no_read:
|
||||||
|
return ""
|
||||||
|
if not os.path.exists("README.md"):
|
||||||
|
return ""
|
||||||
|
with open("README.md", 'rt') as fp:
|
||||||
|
return "<h2>README.md</h2><pre>{}</pre>".format(fp.read().strip())
|
||||||
|
|
||||||
def get_header(opts):
|
def get_header(opts):
|
||||||
opts_str = setup2JSON(opts)
|
opts_str = setup2JSON(opts)
|
||||||
@@ -782,6 +797,10 @@ function alternate(table) {
|
|||||||
margin: 0 0 0 70px;
|
margin: 0 0 0 70px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
}
|
}
|
||||||
|
h2 {
|
||||||
|
padding: 10px 0 8px 0;
|
||||||
|
margin: 0 0 0 30px;
|
||||||
|
}
|
||||||
.container {
|
.container {
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
|
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
|
||||||
@@ -852,6 +871,9 @@ function alternate(table) {
|
|||||||
width: 320;
|
width: 320;
|
||||||
height: 240;
|
height: 240;
|
||||||
}
|
}
|
||||||
|
.container pre {
|
||||||
|
margin: 10px 10px 10px 10px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
'''
|
'''
|
||||||
header = (
|
header = (
|
||||||
@@ -884,9 +906,11 @@ function alternate(table) {
|
|||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
def get_footer():
|
def get_footer(readme):
|
||||||
return """</tbody></table></div>
|
return """</tbody></table>{README}</div>
|
||||||
</body></html>"""
|
</body></html>""".format(
|
||||||
|
README = readme
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_imagefile(fname):
|
def is_imagefile(fname):
|
||||||
|
|||||||
Reference in New Issue
Block a user