parse links from README
This commit is contained in:
@@ -8,6 +8,7 @@ import sys
|
||||
import time
|
||||
import string
|
||||
import json
|
||||
import re
|
||||
import urllib.parse
|
||||
from glob import fnmatch
|
||||
import base64
|
||||
@@ -18,7 +19,17 @@ 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","no_readme")
|
||||
SAFE_OPTS = (
|
||||
"hidden",
|
||||
"title",
|
||||
"parent",
|
||||
"recursive",
|
||||
"images",
|
||||
"media",
|
||||
"includes",
|
||||
"no_readme",
|
||||
)
|
||||
|
||||
|
||||
def setup():
|
||||
""" Setup the command line options """
|
||||
@@ -148,7 +159,7 @@ def HTML2setup(opts):
|
||||
with open(os.path.join(opts.path, opts.filename), "rt") as f:
|
||||
for l in f.readlines():
|
||||
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:])
|
||||
for key in config:
|
||||
if key in SAFE_OPTS:
|
||||
@@ -442,19 +453,28 @@ 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())
|
||||
with open("README.md", "rt") as fp:
|
||||
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):
|
||||
opts_str = setup2JSON(opts)
|
||||
|
||||
js_code = '''
|
||||
js_code = """
|
||||
<script type="text/javascript">
|
||||
/*
|
||||
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>
|
||||
'''
|
||||
css_style = '''
|
||||
"""
|
||||
css_style = """
|
||||
<style>
|
||||
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
||||
* {
|
||||
@@ -826,6 +846,7 @@ function alternate(table) {
|
||||
padding-right: 5px;
|
||||
}
|
||||
a {
|
||||
color: #EB6000;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@@ -875,7 +896,7 @@ function alternate(table) {
|
||||
margin: 10px 10px 10px 10px;
|
||||
}
|
||||
</style>
|
||||
'''
|
||||
"""
|
||||
header = (
|
||||
"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
@@ -901,7 +922,7 @@ function alternate(table) {
|
||||
program="SimpleWebPage",
|
||||
version=VERSION,
|
||||
js_code=js_code,
|
||||
css_style = css_style
|
||||
css_style=css_style,
|
||||
)
|
||||
return header
|
||||
|
||||
|
||||
Reference in New Issue
Block a user