parse links from README

This commit is contained in:
Q
2021-10-12 20:21:55 +03:00
parent 8640a29d00
commit fecebedada

View File

@@ -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:
@@ -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>
@@ -901,7 +922,7 @@ function alternate(table) {
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