|
|
@ -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())) |
|
|
|
|
|
|
|
def md_to_html(md_pad_content, name): |
|
|
|
# Convert Markdown to HTML, using the template from the NAME.template.html pad |
|
|
|
protocol = urlparse(request.base_url).scheme + "://" |
|
|
|
hostname = urlparse(request.base_url).netloc |
|
|
|
domain = protocol + hostname |
|
|
|
template_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/template.html" |
|
|
|
md_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/pad.md" |
|
|
|
# html = pypandoc.convert_text(md_pad_content, 'html', format='md', extra_args=[f'--template={ template_url }', '--standalone']) |
|
|
|
# Convert Markdown to HTML, using the pandoc template from the NAME.template.html pad |
|
|
|
# ---------------------------------------------------------------------------------- |
|
|
|
app_hostname = get_app_hostname() |
|
|
|
app_root = get_app_root() |
|
|
|
template_url = f"{ app_hostname }{ app_root }/{ name }/template.html" |
|
|
|
md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md" |
|
|
|
result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) |
|
|
|
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 |
|
|
|
# html = bleach.clean(html) |
|
|
|
|
|
|
@ -104,6 +107,30 @@ def get_md_metadata(md_pad_content): |
|
|
|
|
|
|
|
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']) |
|
|
@ -142,28 +169,22 @@ def template(name): |
|
|
|
|
|
|
|
@APP.route('/<name>/html/') |
|
|
|
def html(name): |
|
|
|
# only here 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'] |
|
|
|
app_root = get_app_root() |
|
|
|
url = f"{ app_root }/{ name }/preview.html" |
|
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
@APP.route('/<name>/pdf/') |
|
|
|
def pdf(name): |
|
|
|
# only here 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'] |
|
|
|
app_root = get_app_root() |
|
|
|
url = f"{ app_root }/{name}/pagedjs.html" |
|
|
|
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 |
|
|
|
# ////////////////// |
|
|
@ -216,6 +237,14 @@ def pagedjs(name): |
|
|
|
|
|
|
|
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__': |
|
|
|