Browse Source

starting with podcast support + enable dynamic pandoc template from pad, with harcoded app_hostname still (wip)

technodisobedience
mb 12 months ago
parent
commit
916e301615
  1. 71
      octomode.py
  2. 19
      static/main.css
  3. 4
      templates/base.html
  4. 3
      templates/podcast.rss

71
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())) json.load(urlopen(f"{ APP.config['PAD_API_URL'] }/{ api_call }", data=urlencode(arguments).encode()))
def md_to_html(md_pad_content, name): def md_to_html(md_pad_content, name):
# Convert Markdown to HTML, using the template from the NAME.template.html pad # Convert Markdown to HTML, using the pandoc template from the NAME.template.html pad
protocol = urlparse(request.base_url).scheme + "://" # ----------------------------------------------------------------------------------
hostname = urlparse(request.base_url).netloc app_hostname = get_app_hostname()
domain = protocol + hostname app_root = get_app_root()
template_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/template.html" template_url = f"{ app_hostname }{ app_root }/{ name }/template.html"
md_url = f"{ domain }{ APP.config['APPLICATION_ROOT'] }/{ name }/pad.md" md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md"
# html = pypandoc.convert_text(md_pad_content, 'html', format='md', extra_args=[f'--template={ template_url }', '--standalone'])
result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True)
html = result.stdout 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 # Sanitize the Markdown
# html = bleach.clean(html) # html = bleach.clean(html)
@ -104,6 +107,30 @@ def get_md_metadata(md_pad_content):
return metadata 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']) @APP.route('/', methods=['GET', 'POST'])
@ -142,28 +169,22 @@ def template(name):
@APP.route('/<name>/html/') @APP.route('/<name>/html/')
def html(name): def html(name):
# only here we need application root to make all the URLs work..... app_root = get_app_root()
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']
url = f"{ app_root }/{ name }/preview.html" 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(), pad_url=APP.config['PAD_URL'])
@APP.route('/<name>/pdf/') @APP.route('/<name>/pdf/')
def pdf(name): def pdf(name):
# only here we need application root to make all the URLs work..... app_root = get_app_root()
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']
url = f"{ app_root }/{name}/pagedjs.html" url = f"{ app_root }/{name}/pagedjs.html"
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) 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"
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL'])
# ////////////////// # //////////////////
# RENDERED RESOURCES # RENDERED RESOURCES
# ////////////////// # //////////////////
@ -216,6 +237,14 @@ 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>/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__': if __name__ == '__main__':

19
static/main.css

@ -1,7 +1,7 @@
@charset "utf-8"; @charset "utf-8";
:root{ :root{
--highlightcolor: forestgreen; --highlightcolor: #f3c6ff;
} }
body{ body{
@ -32,18 +32,25 @@ div#nav{
line-height: 0; line-height: 0;
margin: 0.75em 15px; margin: 0.75em 15px;
float: left; float: left;
font-size: 32px;
} }
div#nav div#buttons{ div#nav div#buttons{
margin: 0.5em 15px; margin: 0.5em 15px;
float: right; float: right;
} }
div#nav div#buttons a,
div#nav div#buttons a:visited,
div#nav div#buttons a.link{ div#nav div#buttons a.link{
text-decoration: none; text-decoration: none;
color: inherit;
}
div#nav div#buttons a.link{
padding-right: 0.25em;
} }
div#nav div#buttons button{ div#nav div#buttons button{
border: 2px groove var(--highlightcolor); padding: 0.2em 1em 0.4em;
padding: 0.2em 1em 0.3em; /* border: 2px groove var(--highlightcolor); */
border-radius: 1em; /* border-radius: 1em; */
} }
button:hover{ button:hover{
cursor: pointer; cursor: pointer;
@ -106,6 +113,10 @@ body.start-page *{
font-size: 115%; font-size: 115%;
font-weight: bold; font-weight: bold;
} }
body.start-page h1 em.octomode{
font-size: 32px;
}
/* Z-INDEX */ /* Z-INDEX */
div#wrapper, div#wrapper,

4
templates/base.html

@ -38,6 +38,10 @@ window.addEventListener('load', function () {
<a href="{{ url_for('pdf', name=name) }}"><button>pdf</button></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 class="link" href="{{ url_for('pagedjs', 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>
</div>`; </div>`;
document.body.insertBefore(nav, document.body.firstChild); document.body.insertBefore(nav, document.body.firstChild);

3
templates/podcast.rss

@ -0,0 +1,3 @@
RSS FEED FOR: {{ name }}
{{ rss }}
Loading…
Cancel
Save