|
@ -77,16 +77,19 @@ def create_pad_on_first_run(name, ext): |
|
|
json.load(urlopen(f"{ APP.config['PAD_API_URL'] }/{ api_call }", data=urlencode(arguments).encode())) |
|
|
json.load(urlopen(f"{ APP.config['PAD_API_URL'] }/{ api_call }", data=urlencode(arguments).encode())) |
|
|
|
|
|
|
|
|
def md_to_html(md_pad_content, name): |
|
|
def md_to_html(md_pad_content, name): |
|
|
# Convert Markdown to HTML, using the template from the NAME.template.html pad |
|
|
# Convert Markdown to HTML, using the pandoc template from the NAME.template.html pad |
|
|
protocol = urlparse(request.base_url).scheme + "://" |
|
|
# ---------------------------------------------------------------------------------- |
|
|
hostname = urlparse(request.base_url).netloc |
|
|
app_hostname = get_app_hostname() |
|
|
domain = protocol + hostname |
|
|
app_root = get_app_root() |
|
|
template_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/template.html" |
|
|
template_url = f"{ app_hostname }{ app_root }/{ name }/template.html" |
|
|
md_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/pad.md" |
|
|
md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md" |
|
|
# html = pypandoc.convert_text(md_pad_content, 'html', format='md', extra_args=[f'--template={ template_url }', '--standalone']) |
|
|
|
|
|
result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) |
|
|
result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) |
|
|
html = result.stdout |
|
|
html = result.stdout |
|
|
|
|
|
|
|
|
|
|
|
# Convert Markdown to HTML, using the default pandoc template |
|
|
|
|
|
# ---------------------------------------------------------------------------------- |
|
|
|
|
|
# html = pypandoc.convert_text(md_pad_content, 'html', format='md') |
|
|
|
|
|
|
|
|
# Sanitize the Markdown |
|
|
# Sanitize the Markdown |
|
|
# html = bleach.clean(html) |
|
|
# html = bleach.clean(html) |
|
|
|
|
|
|
|
@ -104,6 +107,30 @@ def get_md_metadata(md_pad_content): |
|
|
|
|
|
|
|
|
return metadata |
|
|
return metadata |
|
|
|
|
|
|
|
|
|
|
|
def get_app_root(): |
|
|
|
|
|
# we need application root to make all the URLs work..... |
|
|
|
|
|
if APP.config['APPLICATION_ROOT'] == '/': |
|
|
|
|
|
app_root = '' |
|
|
|
|
|
elif APP.config['APPLICATION_ROOT'].endswith('/'): |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'][:-1] |
|
|
|
|
|
else: |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'] |
|
|
|
|
|
|
|
|
|
|
|
return app_root |
|
|
|
|
|
|
|
|
|
|
|
def get_app_hostname(): |
|
|
|
|
|
# function to get the hostname that the application runs on |
|
|
|
|
|
# for example: localhost:5555, or https://cc.vvvvvvaria.org |
|
|
|
|
|
# TODO: not working atm, this always returns localhost:5555 ...... |
|
|
|
|
|
# -------------------------------------------- |
|
|
|
|
|
# app_protocol = urlparse(request.base_url).scheme + "://" |
|
|
|
|
|
# app_url = urlparse(request.base_url).netloc |
|
|
|
|
|
# app_hostname = app_protocol + app_url |
|
|
|
|
|
|
|
|
|
|
|
app_hostname = "https://circulations.constantvzw.org" # hardcoded for now |
|
|
|
|
|
|
|
|
|
|
|
return app_hostname |
|
|
|
|
|
|
|
|
# --- |
|
|
# --- |
|
|
|
|
|
|
|
|
@APP.route('/', methods=['GET', 'POST']) |
|
|
@APP.route('/', methods=['GET', 'POST']) |
|
@ -142,28 +169,22 @@ def template(name): |
|
|
|
|
|
|
|
|
@APP.route('/<name>/html/') |
|
|
@APP.route('/<name>/html/') |
|
|
def html(name): |
|
|
def html(name): |
|
|
# only here we need application root to make all the URLs work..... |
|
|
app_root = get_app_root() |
|
|
if APP.config['APPLICATION_ROOT'] == '/': |
|
|
|
|
|
app_root = '' |
|
|
|
|
|
elif APP.config['APPLICATION_ROOT'].endswith('/'): |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'][:-1] |
|
|
|
|
|
else: |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'] |
|
|
|
|
|
url = f"{ app_root }/{ name }/preview.html" |
|
|
url = f"{ app_root }/{ name }/preview.html" |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/pdf/') |
|
|
@APP.route('/<name>/pdf/') |
|
|
def pdf(name): |
|
|
def pdf(name): |
|
|
# only here we need application root to make all the URLs work..... |
|
|
app_root = get_app_root() |
|
|
if APP.config['APPLICATION_ROOT'] == '/': |
|
|
|
|
|
app_root = '' |
|
|
|
|
|
elif APP.config['APPLICATION_ROOT'].endswith('/'): |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'][:-1] |
|
|
|
|
|
else: |
|
|
|
|
|
app_root = APP.config['APPLICATION_ROOT'] |
|
|
|
|
|
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>/podcast/') |
|
|
|
|
|
def podcast(name): |
|
|
|
|
|
app_root = get_app_root() |
|
|
|
|
|
url = f"{ app_root }/{name}/podcast.rss" |
|
|
|
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
|
# RENDERED RESOURCES |
|
|
# RENDERED RESOURCES |
|
|
# ////////////////// |
|
|
# ////////////////// |
|
@ -216,6 +237,14 @@ def pagedjs(name): |
|
|
|
|
|
|
|
|
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>/podcast.rss') |
|
|
|
|
|
def rss(name): |
|
|
|
|
|
# TO GENERATE THE PODCAST RSS FEED |
|
|
|
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
rss = "RSS FEED TO BE INSERTED HERE" |
|
|
|
|
|
|
|
|
|
|
|
return render_template('podcast.rss', name=name.strip(), rss=rss) |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|