simplewebage: include README.md

This commit is contained in:
ville rantanen
2021-10-02 12:04:23 +03:00
parent 537f5fcba9
commit 754938ca32

View File

@@ -14,11 +14,11 @@ import base64
import random
from pprint import pprint
VERSION = "20210815"
VERSION = "20211002"
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
AUDIO_EXTENSIONS = ["wav", "mp3", "ogg"]
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():
""" Setup the command line options """
@@ -41,6 +41,13 @@ def setup():
default=False,
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(
"-t",
type=str,
@@ -90,7 +97,6 @@ def setup():
default=False,
help="Make media playable",
)
parser.add_argument(
"--include",
"-i",
@@ -207,6 +213,7 @@ def generate_index(opts):
dirs.sort()
files.sort()
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:
f.write(get_header(opts))
if opts.parent:
@@ -215,7 +222,7 @@ def generate_index(opts):
f.write(get_pathlink(path, di))
for fi in files:
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.close()
return
@@ -435,6 +442,14 @@ iframe {
.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):
opts_str = setup2JSON(opts)
@@ -782,6 +797,10 @@ function alternate(table) {
margin: 0 0 0 70px;
font-family: sans-serif;
}
h2 {
padding: 10px 0 8px 0;
margin: 0 0 0 30px;
}
.container {
margin: 20px;
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
@@ -852,6 +871,9 @@ function alternate(table) {
width: 320;
height: 240;
}
.container pre {
margin: 10px 10px 10px 10px;
}
</style>
'''
header = (
@@ -884,9 +906,11 @@ function alternate(table) {
return header
def get_footer():
return """</tbody></table></div>
</body></html>"""
def get_footer(readme):
return """</tbody></table>{README}</div>
</body></html>""".format(
README = readme
)
def is_imagefile(fname):