diff --git a/octomode.py b/octomode.py index acc5603..a62fe84 100755 --- a/octomode.py +++ b/octomode.py @@ -26,18 +26,20 @@ APP.config.from_pyfile('settings.py') # --- -# my attempt as showing helpful error messages. +# My attempt as showing helpful error messages. +# the class holds an error string to show in the error.html tempalte +# for now mostly for when the space in the yaml meta is missing. class MarkdownRenderError(RuntimeError): def __init__(self, kind, message, original): super().__init__(message) self.kind = kind - self.original = original + self.original = original def get_pad_content(pad_name, ext=""): if ext: pad_name = f'{ pad_name }{ ext }' - print(pad_name) + # print(pad_name) arguments = { 'padID' : pad_name, @@ -55,7 +57,7 @@ def get_pad_content(pad_name, ext=""): content = response['data']['text'] # print("before: " + content) - print( "GET PAD CONTENT" ) + # print( "GET PAD CONTENT" ) for f in pad_content_filters: content = f(content) # print("after: " + content) @@ -70,16 +72,13 @@ def all_pads(): return response -# get all pads that end in .md +# get all pads that end in .md so we can show them on the frontpage def all_publications(): pads = all_pads() pubs = [] - print(pads) if(pads and pads['data'] and pads['data']['padIDs']): for pad in pads['data']['padIDs']: - # if extension is .md add it to pubs if pad.endswith('.md'): - # strip the .md name = pad.removesuffix('.md') pubs.append(name) return pubs @@ -111,6 +110,10 @@ def create_pad_on_first_run(name, ext): def md_to_html(md_pad_content): # Convert Markdown to HTML # html = markdown.markdown(md_pad_content, extensions=['meta', 'attr_list']) # attr_list does not work + + # missing a sapce in the metadata block causes a crash, + # try to show a helpful error message... + # Maybe, we could fix the yaml instead? try: html = pypandoc.convert_text(md_pad_content, 'html', format='md') except RuntimeError as exc: @@ -153,13 +156,6 @@ def get_app_root(): app_root = APP.config['APPLICATION_ROOT'] return app_root - -# def apply_cover(html_str, cover): -# import html -# html_str = str(html_str) -# html_str = html_str.replace('class="cover"', "class='cover' style='background-image: url("+ cover +")'") -# return Markup(html_str) - def get_meta(metadata, key, default=None): return metadata.get(key, [default])[0] @@ -180,6 +176,7 @@ def clean_string(input_string): snake_case_string = re.sub(r'[\s!]+', '_', input_string) return snake_case_string.strip('_') +@APP.template_filter('prettify') # use it in a template with | prettify def prettify_string(input_string): space_string = input_string.replace("_", " ") return space_string.title() @@ -202,7 +199,7 @@ def index(): return redirect(url_for("pad", name=name)) else: pubs = all_publications() - return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL'], prettify_string=prettify_string) + return render_template('start.html', pubs = pubs, home_pad_url=APP.config['HOME_PAD_URL']) @APP.route('//') def main(name): @@ -230,11 +227,11 @@ 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('//impose/') -def impose(name): - app_root = get_app_root() - url = f"{ app_root }/{name}/imposed.html" - return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) +# @APP.route('//impose/') +# def impose(name): +# app_root = get_app_root() +# url = f"{ app_root }/{name}/imposed.html" +# return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) # ////////////////// # RENDERED RESOURCES @@ -275,25 +272,26 @@ def pagedjs(name): title = get_meta(metadata, 'title', 'Untitled') cover = get_meta(metadata, 'cover', None) + print("impose?" + str(request.args.get("impose"))) impose = False #request.args.get("impose") == "true" return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title, cover=cover, impose=impose) -@APP.route('//imposed.html') -def imposed(name): - # TO GENERATE THE IMPOSED WEBPAGE - md_pad_content = get_pad_content(name, ext='.md') - try: - html = md_to_html(md_pad_content) - except MarkdownRenderError as exc: - return render_markdown_error(name, exc) - metadata = get_md_metadata(md_pad_content) - lang = get_meta(metadata, 'language', 'en') - title = get_meta(metadata, 'title', 'Untitled') - cover = get_meta(metadata, 'cover', None) +# @APP.route('//imposed.html') +# def imposed(name): +# # TO GENERATE THE IMPOSED WEBPAGE +# md_pad_content = get_pad_content(name, ext='.md') +# try: +# html = md_to_html(md_pad_content) +# except MarkdownRenderError as exc: +# return render_markdown_error(name, exc) +# metadata = get_md_metadata(md_pad_content) +# lang = get_meta(metadata, 'language', 'en') +# title = get_meta(metadata, 'title', 'Untitled') +# cover = get_meta(metadata, 'cover', None) - impose = True #request.args.get("impose") == "true" +# impose = True #request.args.get("impose") == "true" - return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title, cover=cover, impose=impose) +# return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title, cover=cover, impose=impose) # ////////////////// diff --git a/templates/base.html b/templates/base.html index 7cb041d..abd4a7c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,26 +2,14 @@ - {{ name }} in octomode + {{ name | prettify }} in octomode {% block head %} {% endblock %} -
- {% block content %} - {% endblock %} -
- - {% block footer %} {% endblock %} diff --git a/templates/pdf.html b/templates/pdf.html index c0fb711..f57dee7 100644 --- a/templates/pdf.html +++ b/templates/pdf.html @@ -1,9 +1,5 @@ {% extends "base.html" %} -{% block head %} -hallo -{% endblock %} - {% block content %} {% endblock %} @@ -25,8 +21,6 @@ window.addEventListener('load', function () { head.insertBefore(cssLink, head.firstChild); const nav = document.getElementById('buttons'); - // insert the IMPOSE button - // const impose = ''; // Insert the SAVE button const save = ''; diff --git a/templates/start.html b/templates/start.html index f1368df..467e03f 100644 --- a/templates/start.html +++ b/templates/start.html @@ -19,7 +19,7 @@

Below a list of the publications on the server.