diff --git a/octomode.py b/octomode.py index df2944b..f85a957 100755 --- a/octomode.py +++ b/octomode.py @@ -4,6 +4,7 @@ from flask import Flask, request, render_template, render_template_string, redir from urllib.request import urlopen from urllib.parse import urlencode, urlparse import subprocess +from jinja2 import Template # To sanitize Flask input fields from markupsafe import Markup, escape @@ -195,7 +196,13 @@ def wildcardtemplate(name): @APP.route('//wildcard/') def wildcard(name): 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('//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()) # ////////////////// @@ -243,7 +250,7 @@ def preview(name): @APP.route('//pagedjs.html') def pagedjs(name): - # TO GENERATE THE PAGED.JS WEBPAGE + # TO GENERATE THE PAGED.JS PAGE md_pad_content = get_pad_content(name, ext='.md') html = md_to_html(md_pad_content, name) 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) -@APP.route('//wildcard.raw') +@APP.route('//wildcard.html') def wildcardpage(name): md_pad_content = get_pad_content(name, ext='.md') wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html') audio = [] for line in md_pad_content.splitlines(): - # if any(ext in line for ext in [".mp3", ".ogg"]): if ".mp3" in line: audio.append(line) + elif ".ogg" in line: + audio.append(line) return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) @APP.route('//podcast.rss') def rss(name): + # parse for audio links md_pad_content = get_pad_content(name, ext='.md') audio = [] for line in md_pad_content.splitlines(): - # if any(ext in line for ext in [".mp3", ".ogg"]): if ".mp3" in line: audio.append(line) - - return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} + # parse metadata + 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'} # ////////////////// diff --git a/templates/base.html b/templates/base.html index f3760e3..57a8ff2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -47,6 +47,8 @@ window.addEventListener('load', function () { 🔗 + + 🔗 `; diff --git a/templates/podcast.rss b/templates/podcast.rss index f35b6fd..edee91a 100644 --- a/templates/podcast.rss +++ b/templates/podcast.rss @@ -1,18 +1,16 @@ - {{title}} - https://later + {{ title }} + {{ octomode_link }} Podcast generated etcot. builtdate..todo - - + {% for link in audio %} todo - + {% endfor %} -