|
@ -5,6 +5,7 @@ from urllib.request import urlopen |
|
|
from urllib.parse import urlencode, urlparse |
|
|
from urllib.parse import urlencode, urlparse |
|
|
import subprocess |
|
|
import subprocess |
|
|
from jinja2 import Template |
|
|
from jinja2 import Template |
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
# To sanitize Flask input fields |
|
|
# To sanitize Flask input fields |
|
|
from markupsafe import Markup, escape |
|
|
from markupsafe import Markup, escape |
|
@ -188,6 +189,18 @@ def pdf(name): |
|
|
url = f"{ app_root }/{name}/pagedjs.html" |
|
|
url = f"{ app_root }/{name}/pagedjs.html" |
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/pdfmyk/') |
|
|
|
|
|
def pdfmyk(name): |
|
|
|
|
|
app_root = get_app_root() |
|
|
|
|
|
url = f"{ app_root }/{name}/pagedjs-myk.html" |
|
|
|
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/pdfck/') |
|
|
|
|
|
def pdfck(name): |
|
|
|
|
|
app_root = get_app_root() |
|
|
|
|
|
url = f"{ app_root }/{name}/pagedjs-ck.html" |
|
|
|
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/wildcard-template/') |
|
|
@APP.route('/<name>/wildcard-template/') |
|
|
def wildcardtemplate(name): |
|
|
def wildcardtemplate(name): |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.wildcard-template.html" |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.wildcard-template.html" |
|
@ -212,9 +225,8 @@ def podcast(name): |
|
|
|
|
|
|
|
|
@APP.route('/<name>/stylesheet.css') |
|
|
@APP.route('/<name>/stylesheet.css') |
|
|
def css(name): |
|
|
def css(name): |
|
|
css = get_pad_content(name, '.css') |
|
|
css = get_pad_content(name, ext='.css') |
|
|
# Insert CSS sanitizer here. |
|
|
# Insert CSS sanitizer here. |
|
|
|
|
|
|
|
|
return css, 200, {'Content-Type': 'text/css; charset=utf-8'} |
|
|
return css, 200, {'Content-Type': 'text/css; charset=utf-8'} |
|
|
|
|
|
|
|
|
# only used for the pandoc command using the subprocess |
|
|
# only used for the pandoc command using the subprocess |
|
@ -252,25 +264,78 @@ def preview(name): |
|
|
def pagedjs(name): |
|
|
def pagedjs(name): |
|
|
# TO GENERATE THE PAGED.JS PAGE |
|
|
# TO GENERATE THE PAGED.JS PAGE |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
|
|
|
|
|
|
### HACKSS START HERE |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.colorz})", r"\1.myk-ck/\2.jpg\3", md_pad_content) |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.mono})", r"\1.ck/\2-col.jpg\3", md_pad_content) |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.othermono})", r"\1.myk/\2-col.jpg\3", md_pad_content) |
|
|
|
|
|
### HACKSS END HERE |
|
|
|
|
|
|
|
|
html = md_to_html(md_pad_content, name) |
|
|
html = md_to_html(md_pad_content, name) |
|
|
metadata = get_md_metadata(md_pad_content) |
|
|
metadata = get_md_metadata(md_pad_content) |
|
|
lang = metadata['language'][0] |
|
|
lang = metadata['language'][0] |
|
|
title = metadata['title'][0] |
|
|
title = metadata['title'][0] |
|
|
|
|
|
|
|
|
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/pagedjs-myk.html') |
|
|
|
|
|
def pagedjsmyk(name): |
|
|
|
|
|
# TO GENERATE THE PAGED.JS PAGE |
|
|
|
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
|
|
|
|
|
|
### HACKSS START HERE |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.colorz})", r"\1.myk/\2.jpg\3", md_pad_content) |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.othermono})", r"\1.myk/\2.jpg\3", md_pad_content) |
|
|
|
|
|
### HACKSS END HERE |
|
|
|
|
|
|
|
|
|
|
|
html = md_to_html(md_pad_content, name) |
|
|
|
|
|
metadata = get_md_metadata(md_pad_content) |
|
|
|
|
|
lang = metadata['language'][0] |
|
|
|
|
|
title = metadata['title'][0] |
|
|
|
|
|
return render_template('pagedjs-myk.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/pagedjs-ck.html') |
|
|
|
|
|
def pagedjsck(name): |
|
|
|
|
|
# TO GENERATE THE PAGED.JS PAGE |
|
|
|
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
|
|
|
|
|
|
### HACKSS START HERE |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.colorz})", r"\1.ck/\2.jpg\3", md_pad_content) |
|
|
|
|
|
md_pad_content=re.sub(r"(!.+/publication/images/)(.+)(\){.mono})", r"\1.ck/\2.jpg\3", md_pad_content) |
|
|
|
|
|
### HACKSS END HERE |
|
|
|
|
|
|
|
|
|
|
|
html = md_to_html(md_pad_content, name) |
|
|
|
|
|
metadata = get_md_metadata(md_pad_content) |
|
|
|
|
|
lang = metadata['language'][0] |
|
|
|
|
|
title = metadata['title'][0] |
|
|
|
|
|
return render_template('pagedjs-ck.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/wildcard.html') |
|
|
@APP.route('/<name>/wildcard.html') |
|
|
def wildcardpage(name): |
|
|
def wildcardpage(name): |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html') |
|
|
wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html') |
|
|
audio = [] |
|
|
audio = [] |
|
|
|
|
|
pdf = [] |
|
|
|
|
|
images = [] |
|
|
|
|
|
allall = [] |
|
|
for line in md_pad_content.splitlines(): |
|
|
for line in md_pad_content.splitlines(): |
|
|
if ".mp3" in line: |
|
|
slines=re.split("\s|\"|\(|\)|>|<",line) |
|
|
audio.append(line) |
|
|
for sline in slines: |
|
|
elif ".ogg" in line: |
|
|
if "http" in sline and sline not in allall: |
|
|
audio.append(line) |
|
|
if ".mp3" in sline: |
|
|
|
|
|
audio.append(sline) |
|
|
return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) |
|
|
allall.append(sline) |
|
|
|
|
|
elif ".ogg" in sline: |
|
|
|
|
|
audio.append(sline) |
|
|
|
|
|
allall.append(sline) |
|
|
|
|
|
elif ".pdf" in sline: |
|
|
|
|
|
pdf.append(sline) |
|
|
|
|
|
allall.append(sline) |
|
|
|
|
|
elif ".jpg" in sline: |
|
|
|
|
|
images.append(sline) |
|
|
|
|
|
allall.append(sline) |
|
|
|
|
|
|
|
|
|
|
|
return render_template_string(wildcard_template_pad_content, name=name.strip(), allall=allall, pdf=pdf, images=images, audio=audio) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/podcast.rss') |
|
|
@APP.route('/<name>/podcast.rss') |
|
|
def rss(name): |
|
|
def rss(name): |
|
|