|
@ -4,6 +4,7 @@ from flask import Flask, request, render_template, render_template_string, redir |
|
|
from urllib.request import urlopen |
|
|
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 |
|
|
|
|
|
|
|
|
# To sanitize Flask input fields |
|
|
# To sanitize Flask input fields |
|
|
from markupsafe import Markup, escape |
|
|
from markupsafe import Markup, escape |
|
@ -195,7 +196,13 @@ def wildcardtemplate(name): |
|
|
@APP.route('/<name>/wildcard/') |
|
|
@APP.route('/<name>/wildcard/') |
|
|
def wildcard(name): |
|
|
def wildcard(name): |
|
|
app_root = get_app_root() |
|
|
app_root = get_app_root() |
|
|
url = f"{ app_root }/{name}/wildcard.raw" |
|
|
url = url_for("wildcardpage", name=name) |
|
|
|
|
|
return render_template('iframe.html', url=url, name=name.strip()) |
|
|
|
|
|
|
|
|
|
|
|
@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()) |
|
|
return render_template('iframe.html', url=url, name=name.strip()) |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
@ -243,7 +250,7 @@ def preview(name): |
|
|
|
|
|
|
|
|
@APP.route('/<name>/pagedjs.html') |
|
|
@APP.route('/<name>/pagedjs.html') |
|
|
def pagedjs(name): |
|
|
def pagedjs(name): |
|
|
# TO GENERATE THE PAGED.JS WEBPAGE |
|
|
# TO GENERATE THE PAGED.JS PAGE |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
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) |
|
@ -252,28 +259,39 @@ 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>/wildcard.raw') |
|
|
@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 = [] |
|
|
for line in md_pad_content.splitlines(): |
|
|
for line in md_pad_content.splitlines(): |
|
|
# if any(ext in line for ext in [".mp3", ".ogg"]): |
|
|
|
|
|
if ".mp3" in line: |
|
|
if ".mp3" in line: |
|
|
audio.append(line) |
|
|
audio.append(line) |
|
|
|
|
|
elif ".ogg" in line: |
|
|
|
|
|
audio.append(line) |
|
|
|
|
|
|
|
|
return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) |
|
|
return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/podcast.rss') |
|
|
@APP.route('/<name>/podcast.rss') |
|
|
def rss(name): |
|
|
def rss(name): |
|
|
|
|
|
# parse for audio links |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
audio = [] |
|
|
audio = [] |
|
|
for line in md_pad_content.splitlines(): |
|
|
for line in md_pad_content.splitlines(): |
|
|
# if any(ext in line for ext in [".mp3", ".ogg"]): |
|
|
|
|
|
if ".mp3" in line: |
|
|
if ".mp3" in line: |
|
|
audio.append(line) |
|
|
audio.append(line) |
|
|
|
|
|
# parse metadata |
|
|
return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} |
|
|
metadata = get_md_metadata(md_pad_content) |
|
|
|
|
|
title = metadata['title'][0] |
|
|
|
|
|
app_url = get_app_hostname() + get_app_root() |
|
|
|
|
|
octomode_link = app_url + url_for("main", name=name) |
|
|
|
|
|
rss_link = app_url + url_for("rss", name=name) |
|
|
|
|
|
# render podcast.rss template |
|
|
|
|
|
with open("templates/podcast.rss", "r") as t: |
|
|
|
|
|
template = Template(t.read()) |
|
|
|
|
|
rss = template.render(name=name.strip(), title=title, audio=audio, octomode_link=octomode_link, rss_link=rss_link) |
|
|
|
|
|
|
|
|
|
|
|
return rss, 200, {'Content-Type': 'text/xml; charset=utf-8'} |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
|
|
|
|
|
|
|