parse links from README
This commit is contained in:
@@ -8,6 +8,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import string
|
import string
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from glob import fnmatch
|
from glob import fnmatch
|
||||||
import base64
|
import base64
|
||||||
@@ -18,7 +19,17 @@ 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","no_readme")
|
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 """
|
||||||
@@ -148,7 +159,7 @@ def HTML2setup(opts):
|
|||||||
with open(os.path.join(opts.path, opts.filename), "rt") as f:
|
with open(os.path.join(opts.path, opts.filename), "rt") as f:
|
||||||
for l in f.readlines():
|
for l in f.readlines():
|
||||||
if l.find('<meta name="SimpleWebPageSetup"') > -1:
|
if l.find('<meta name="SimpleWebPageSetup"') > -1:
|
||||||
content = l[l.find('content=') :].rstrip("'/>\n")
|
content = l[l.find("content=") :].rstrip("'/>\n")
|
||||||
config = json.loads(content[9:])
|
config = json.loads(content[9:])
|
||||||
for key in config:
|
for key in config:
|
||||||
if key in SAFE_OPTS:
|
if key in SAFE_OPTS:
|
||||||
@@ -223,7 +234,7 @@ def generate_index(opts):
|
|||||||
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(readme))
|
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
|
||||||
|
|
||||||
@@ -287,7 +298,7 @@ def get_filelink(path, fname, images=False, media=False):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_download_lines(files, recursive = False):
|
def get_download_lines(files, recursive=False):
|
||||||
s = "\n<!--\n"
|
s = "\n<!--\n"
|
||||||
for f in files:
|
for f in files:
|
||||||
s += "#FILE %s\n" % (urllib.parse.quote(f),)
|
s += "#FILE %s\n" % (urllib.parse.quote(f),)
|
||||||
@@ -442,19 +453,28 @@ iframe {
|
|||||||
.replace("SECRET", secret, 1)
|
.replace("SECRET", secret, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_readme(path, no_read):
|
def get_readme(path, no_read):
|
||||||
|
|
||||||
if no_read:
|
if no_read:
|
||||||
return ""
|
return ""
|
||||||
if not os.path.exists("README.md"):
|
if not os.path.exists("README.md"):
|
||||||
return ""
|
return ""
|
||||||
with open("README.md", 'rt') as fp:
|
with open("README.md", "rt") as fp:
|
||||||
return "<h2>README.md</h2><pre>{}</pre>".format(fp.read().strip())
|
return "<h2>README.md</h2><pre>{}</pre>".format(
|
||||||
|
re.sub(
|
||||||
|
r"(https?:\/\/[\w\.,\-\@?^=%&:/~\+#]+)",
|
||||||
|
'<a href="\\1">\\1</a>',
|
||||||
|
fp.read().strip(),
|
||||||
|
flags=re.IGNORECASE,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_header(opts):
|
def get_header(opts):
|
||||||
opts_str = setup2JSON(opts)
|
opts_str = setup2JSON(opts)
|
||||||
|
|
||||||
js_code = '''
|
js_code = """
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
/*
|
/*
|
||||||
Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
|
Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
|
||||||
@@ -778,8 +798,8 @@ function alternate(table) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
'''
|
"""
|
||||||
css_style = '''
|
css_style = """
|
||||||
<style>
|
<style>
|
||||||
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
||||||
* {
|
* {
|
||||||
@@ -826,6 +846,7 @@ function alternate(table) {
|
|||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
|
color: #EB6000;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,7 +896,7 @@ function alternate(table) {
|
|||||||
margin: 10px 10px 10px 10px;
|
margin: 10px 10px 10px 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
'''
|
"""
|
||||||
header = (
|
header = (
|
||||||
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
<html>
|
<html>
|
||||||
@@ -896,12 +917,12 @@ function alternate(table) {
|
|||||||
<table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody>
|
<table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody>
|
||||||
"""
|
"""
|
||||||
).format(
|
).format(
|
||||||
title = opts.title,
|
title=opts.title,
|
||||||
config = opts_str,
|
config=opts_str,
|
||||||
program = "SimpleWebPage",
|
program="SimpleWebPage",
|
||||||
version = VERSION,
|
version=VERSION,
|
||||||
js_code = js_code,
|
js_code=js_code,
|
||||||
css_style = css_style
|
css_style=css_style,
|
||||||
)
|
)
|
||||||
return header
|
return header
|
||||||
|
|
||||||
@@ -909,7 +930,7 @@ function alternate(table) {
|
|||||||
def get_footer(readme):
|
def get_footer(readme):
|
||||||
return """</tbody></table>{README}</div>
|
return """</tbody></table>{README}</div>
|
||||||
</body></html>""".format(
|
</body></html>""".format(
|
||||||
README = readme
|
README=readme
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user