From d2c9fd6cba3fd625f88c833ca3d7769e41f6be70 Mon Sep 17 00:00:00 2001 From: "mb@circulations.constantvzw.org" Date: Thu, 30 Nov 2023 13:41:07 +0000 Subject: [PATCH] sync with server and repo --- .gitignore | 1 + Makefile | 2 +- octomode.py | 94 ++++++++++++------- requirements.txt | 3 +- static/main.css | 3 + templates/base.html | 16 +++- ...late.html => default.pandoc-template.html} | 0 templates/default.wildcard-template.html | 15 +++ templates/podcast.rss | 30 +++--- 9 files changed, 108 insertions(+), 56 deletions(-) rename templates/{default.template.html => default.pandoc-template.html} (100%) create mode 100644 templates/default.wildcard-template.html diff --git a/.gitignore b/.gitignore index 32ac21b..4004a81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv .env __pycache__ +error.log diff --git a/Makefile b/Makefile index 7e30820..9125b74 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,4 @@ local: action: @if [ ! -f ".venv/bin/gunicorn" ]; then .venv/bin/pip install gunicorn; fi - @SCRIPT_NAME=${OCTOMODE_APPLICATION_ROOT} .venv/bin/gunicorn -b localhost:${OCTOMODE_PORTNUMBER} --reload octomode:APP + @SCRIPT_NAME=${OCTOMODE_APPLICATION_ROOT} .venv/bin/gunicorn --error-logfile error.log --capture-output -b localhost:${OCTOMODE_PORTNUMBER} --reload octomode:APP diff --git a/octomode.py b/octomode.py index 14b401f..df2944b 100755 --- a/octomode.py +++ b/octomode.py @@ -1,6 +1,6 @@ import os import json -from flask import Flask, request, render_template, redirect, url_for +from flask import Flask, request, render_template, render_template_string, redirect, url_for from urllib.request import urlopen from urllib.parse import urlencode, urlparse import subprocess @@ -63,8 +63,10 @@ def create_pad_on_first_run(name, ext): default_template = 'templates/default.md' elif 'css' in ext: default_template = 'templates/default.css' - elif 'template' in ext: - default_template = 'templates/default.template.html' + elif 'pandoc-template' in ext: + default_template = 'templates/default.pandoc-template.html' + elif 'wildcard-template' in ext: + default_template = 'templates/default.wildcard-template.html' default_template = open(default_template).read() # Create pad and add the default template @@ -79,20 +81,22 @@ def create_pad_on_first_run(name, ext): def md_to_html(md_pad_content, name): # 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" - APP.logger.info("template_url", template_url) - APP.logger.info("md_url", md_url) - result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) - html = result.stdout - APP.logger.info("html", html) - APP.logger.info("result.stderr", result.stderr) + #app_hostname = get_app_hostname() + #app_root = get_app_root() + #template_url = f"{ app_hostname }{ app_root }/{ name }/template.html" + #template_url = "http://127.0.0.1:5555/octomode/techno/template.html" + #md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md" + #md_url = "http://127.0.0.1:5555/octomode/techno/pad.md" + #APP.logger.info("template_url", template_url) + #APP.logger.info("md_url", md_url) + #result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) + #html = result.stdout + #APP.logger.info("html", html) + #APP.logger.info("result.stderr", result.stderr) # Convert Markdown to HTML, using the default pandoc template # ---------------------------------------------------------------------------------- - # html = pypandoc.convert_text(md_pad_content, 'html', format='md') + html = pypandoc.convert_text(md_pad_content, 'html', format='md') # Sanitize the Markdown # html = bleach.clean(html) @@ -145,7 +149,7 @@ def index(): if name: # This is when the environment is "created" # The pads are filled with the default templates (pad, stylesheet, template) - exts = ['.md', '.css', '.template.html'] + exts = ['.md', '.css', '.pandoc-template.html', '.wildcard-template.html'] for ext in exts: create_pad_on_first_run(name, ext) return redirect(url_for("pad", name=name)) @@ -166,16 +170,16 @@ def stylesheet(name): url = f"{ APP.config['PAD_URL'] }/{ name }.css" return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) -@APP.route('//template/') -def template(name): - url = f"{ APP.config['PAD_URL'] }/{ name }.template.html" +@APP.route('//pandoc-template/') +def pandoctemplate(name): + url = f"{ APP.config['PAD_URL'] }/{ name }.pandoc-template.html" return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) @APP.route('//html/') def html(name): 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']) + return render_template('iframe.html', url=url, name=name.strip()) @APP.route('//pdf/') def pdf(name): @@ -183,12 +187,17 @@ def pdf(name): 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" +@APP.route('//wildcard-template/') +def wildcardtemplate(name): + url = f"{ APP.config['PAD_URL'] }/{ name }.wildcard-template.html" return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) +@APP.route('//wildcard/') +def wildcard(name): + app_root = get_app_root() + url = f"{ app_root }/{name}/wildcard.raw" + return render_template('iframe.html', url=url, name=name.strip()) + # ////////////////// # RENDERED RESOURCES # ////////////////// @@ -201,19 +210,21 @@ def css(name): return css, 200, {'Content-Type': 'text/css; charset=utf-8'} -@APP.route('//pad.md') -def md(name): - # TO GENERATE THE CONTENT IN MARKDOWN - template_pad_content = get_pad_content(name, ext='.md') - - return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} +# only used for the pandoc command using the subprocess +# --- +#@APP.route('//pad.md') +#def md(name): +# # TO GENERATE THE CONTENT IN MARKDOWN +# template_pad_content = get_pad_content(name, ext='.md') +# +# return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} -@APP.route('//template.html') -def pandoctemplate(name): - # TO GENERATE THE PANDOC TEMPLATE - template_pad_content = get_pad_content(name, ext='.template.html') +@APP.route('//pandoc-template.html') +def pandoctemplatehtml(name): + # TO GENERATE THE TEMPLATE AS HTML FILE + template_pad_content = get_pad_content(name, ext='.pandoc-template.html') - return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} + return template_pad_content, 200, {'Content-Type': 'text/html; charset=utf-8'} @APP.route('//preview.html') def preview(name): @@ -241,9 +252,20 @@ def pagedjs(name): return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) +@APP.route('//wildcard.raw') +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) + + return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) + @APP.route('//podcast.rss') def rss(name): - # TO GENERATE THE PODCAST RSS FEED md_pad_content = get_pad_content(name, ext='.md') audio = [] for line in md_pad_content.splitlines(): @@ -251,7 +273,7 @@ def rss(name): if ".mp3" in line: audio.append(line) - return render_template('podcast.rss', name=name.strip(), rss=rss, audio=audio) + return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} # ////////////////// diff --git a/requirements.txt b/requirements.txt index fe0b214..cbc4c5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ flask +pandoc pypandoc markdown -python-dotenv \ No newline at end of file +python-dotenv diff --git a/static/main.css b/static/main.css index d5ec553..00a1242 100644 --- a/static/main.css +++ b/static/main.css @@ -33,6 +33,7 @@ div#nav{ margin: 0.75em 15px; float: left; font-size: 32px; + z-index: -1; } div#nav div#buttons{ margin: 0.5em 15px; @@ -49,6 +50,8 @@ div#nav{ } div#nav div#buttons button{ padding: 0.2em 1em 0.4em; + font-variant-caps: all-small-caps; + font-family: monospace; /* border: 2px groove var(--highlightcolor); */ /* border-radius: 1em; */ } diff --git a/templates/base.html b/templates/base.html index e478344..f3760e3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -30,18 +30,24 @@ window.addEventListener('load', function () { 🔗 - - 🔗 + 🔗 - - 🔗 - 🔗 + + 🔗 + + + 🔗 + + `; document.body.insertBefore(nav, document.body.firstChild); diff --git a/templates/default.template.html b/templates/default.pandoc-template.html similarity index 100% rename from templates/default.template.html rename to templates/default.pandoc-template.html diff --git a/templates/default.wildcard-template.html b/templates/default.wildcard-template.html new file mode 100644 index 0000000..0580285 --- /dev/null +++ b/templates/default.wildcard-template.html @@ -0,0 +1,15 @@ +PODCAST RSS FEED FOR: {{ name }} + +

+ +audio found: + +

+ +{% for link in audio %} + + +

+ +{% endfor %} + diff --git a/templates/podcast.rss b/templates/podcast.rss index c0f7e65..f35b6fd 100644 --- a/templates/podcast.rss +++ b/templates/podcast.rss @@ -1,14 +1,18 @@ -PODCAST RSS FEED FOR: {{ name }} + + + + {{title}} + https://later + Podcast generated etcot. + builtdate..todo + + + {% for link in audio %} + + todo + + + {% endfor %} -

- -audio found: - -

- -{% for link in audio %} - - -

- -{% endfor %} +
+