Browse Source

sync with server and repo

technodisobedience
parent
commit
d2c9fd6cba
  1. 1
      .gitignore
  2. 2
      Makefile
  3. 94
      octomode.py
  4. 3
      requirements.txt
  5. 3
      static/main.css
  6. 16
      templates/base.html
  7. 0
      templates/default.pandoc-template.html
  8. 15
      templates/default.wildcard-template.html
  9. 30
      templates/podcast.rss

1
.gitignore

@ -1,3 +1,4 @@
.venv
.env
__pycache__
error.log

2
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

94
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('/<name>/template/')
def template(name):
url = f"{ APP.config['PAD_URL'] }/{ name }.template.html"
@APP.route('/<name>/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('/<name>/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('/<name>/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('/<name>/podcast/')
def podcast(name):
app_root = get_app_root()
url = f"{ app_root }/{name}/podcast.rss"
@APP.route('/<name>/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('/<name>/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('/<name>/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('/<name>/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('/<name>/template.html')
def pandoctemplate(name):
# TO GENERATE THE PANDOC TEMPLATE
template_pad_content = get_pad_content(name, ext='.template.html')
@APP.route('/<name>/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('/<name>/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('/<name>/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('/<name>/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'}
# //////////////////

3
requirements.txt

@ -1,4 +1,5 @@
flask
pandoc
pypandoc
markdown
python-dotenv
python-dotenv

3
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; */
}

16
templates/base.html

@ -30,18 +30,24 @@ window.addEventListener('load', function () {
<a href="{{ url_for('stylesheet', name=name) }}"><button>stylesheet</button></a>
<a class="link" href="{{ pad_url }}/{{ name }}.css" target="_blank">🔗</a>
<a href="{{ url_for('template', name=name) }}"><button>template</button></a>
<a class="link" href="{{ pad_url }}/{{ name }}.template.html" target="_blank">🔗</a>
<!--
<a href="{{ url_for('pandoctemplate', name=name) }}"><button>pandoc template</button></a>
<a class="link" href="{{ pad_url }}/{{ name }}.pandoc-template.html" target="_blank">🔗</a>
-->
<a href="{{ url_for('html', name=name) }}"><button>html</button></a>
<a class="link" href="{{ url_for('preview', name=name) }}" target="_blank">🔗</a>
<a href="{{ url_for('podcast', name=name) }}"><button>podcast</button></a>
<a class="link" href="{{ url_for('rss', name=name) }}" target="_blank">🔗</a>
<a href="{{ url_for('pdf', name=name) }}"><button>pdf</button></a>
<a class="link" href="{{ url_for('pagedjs', name=name) }}" target="_blank">🔗</a>
<a href="{{ url_for('wildcardtemplate', name=name) }}"><button>* template</button></a>
<a class="link" href="{{ pad_url }}/{{ name }}.wildcard-template.html" target="_blank">🔗</a>
<a href="{{ url_for('wildcard', name=name) }}"><button>*</button></a>
<a class="link" href="{{ url_for('wildcardpage', name=name) }}" target="_blank"> 🔗</a>
</div>`;
document.body.insertBefore(nav, document.body.firstChild);

0
templates/default.template.html → templates/default.pandoc-template.html

15
templates/default.wildcard-template.html

@ -0,0 +1,15 @@
PODCAST RSS FEED FOR: {{ name }}
<br><br>
audio found:
<br><br>
{% for link in audio %}
<audio src="{{ link }}" controls></audio>
<br><br>
{% endfor %}

30
templates/podcast.rss

@ -1,14 +1,18 @@
PODCAST RSS FEED FOR: {{ name }}
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{title}}</title>
<link>https://later</link>
<description>Podcast generated etcot.</description>
<lastBuildDate>builtdate..todo</lastBuildDate>
<atom:link href="todo.xml" rel="self" type="application/rss+xml" />
{% for link in audio %}
<item>
<pubDate>todo</pubDate>
<enclosure url="{{link}}" type="audio/mpeg" />
</item>
{% endfor %}
<br><br>
audio found:
<br><br>
{% for link in audio %}
<audio src="{{ link }}" controls></audio>
<br><br>
{% endfor %}
</channel>
</rss>

Loading…
Cancel
Save