Browse Source

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

technodisobedience
mb 1 year 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()))
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('/<name>/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('/<name>/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('/<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
# //////////////////
@ -216,6 +237,14 @@ def pagedjs(name):
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__':

19
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,

4
templates/base.html

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

3
templates/podcast.rss

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