From 916e30161598bb8b80312838641dcfcd79fd5e50 Mon Sep 17 00:00:00 2001 From: mb Date: Thu, 30 Nov 2023 10:01:57 +0100 Subject: [PATCH] starting with podcast support + enable dynamic pandoc template from pad, with harcoded app_hostname still (wip) --- octomode.py | 71 ++++++++++++++++++++++++++++++------------- static/main.css | 19 +++++++++--- templates/base.html | 4 +++ templates/podcast.rss | 3 ++ 4 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 templates/podcast.rss diff --git a/octomode.py b/octomode.py index b3159ae..4801d96 100755 --- a/octomode.py +++ b/octomode.py @@ -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('//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('//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('//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('//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__': diff --git a/static/main.css b/static/main.css index 27d3d97..d5ec553 100644 --- a/static/main.css +++ b/static/main.css @@ -1,7 +1,7 @@ @charset "utf-8"; :root{ - --highlightcolor: forestgreen; + --highlightcolor: #f3c6ff; } body{ @@ -32,18 +32,25 @@ div#nav{ line-height: 0; margin: 0.75em 15px; float: left; + font-size: 32px; } div#nav div#buttons{ margin: 0.5em 15px; float: right; } + div#nav div#buttons a, + div#nav div#buttons a:visited, div#nav div#buttons a.link{ text-decoration: none; + color: inherit; + } + div#nav div#buttons a.link{ + padding-right: 0.25em; } div#nav div#buttons button{ - border: 2px groove var(--highlightcolor); - padding: 0.2em 1em 0.3em; - border-radius: 1em; + padding: 0.2em 1em 0.4em; + /* border: 2px groove var(--highlightcolor); */ + /* border-radius: 1em; */ } button:hover{ cursor: pointer; @@ -106,6 +113,10 @@ body.start-page *{ font-size: 115%; font-weight: bold; } +body.start-page h1 em.octomode{ + font-size: 32px; +} + /* Z-INDEX */ div#wrapper, diff --git a/templates/base.html b/templates/base.html index 2e3e278..3aefd7b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -38,6 +38,10 @@ window.addEventListener('load', function () { 🔗 + + + 🔗 + `; document.body.insertBefore(nav, document.body.firstChild); diff --git a/templates/podcast.rss b/templates/podcast.rss new file mode 100644 index 0000000..9176d66 --- /dev/null +++ b/templates/podcast.rss @@ -0,0 +1,3 @@ +RSS FEED FOR: {{ name }} + +{{ rss }}