chaging imposition functions

This commit is contained in:
my 2026-01-30 16:06:43 +01:00
parent e19324c220
commit b16325d0fe
4 changed files with 45 additions and 62 deletions

View file

@ -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('/<name>/')
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('/<name>/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('/<name>/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('/<name>/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('/<name>/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)
# //////////////////

View file

@ -2,26 +2,14 @@
<html lang='en'>
<head>
<meta charset="utf-8" />
<title>{{ name }} in octomode</title>
<title>{{ name | prettify }} in octomode</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
{% block head %}
{% endblock %}
</head>
<body>
<div id="wrapper">
{% block content %}
{% endblock %}
</div>
</body>
<script>
window.addEventListener('load', function () {
// Insert the nav buttons, after the page is loaded
const nav = document.createElement('div');
nav.id = 'nav';
nav.innerHTML = `
<h1>{{ name }} <a href="{{ url_for('index') }}"><em class="octomode">in octomode</em></a></h1>
<div id="nav">
<h1>{{ name | prettify }} <a href="{{ url_for('index') }}"><em class="octomode">in octomode</em></a></h1>
<div id="buttons">
<a href="{{ url_for('pad', name=name) }}"><button>pad</button></a>
@ -36,13 +24,16 @@ window.addEventListener('load', function () {
<a href="{{ url_for('pdf', name=name) }}"><button>layout</button></a>
<a href="{{ url_for('impose', name=name) }}"><button>impose</button></a>
</div>`;
</div>
</nav>
<div id="wrapper">
{% block content %}
{% endblock %}
</div>
</body>
document.body.insertBefore(nav, document.body.firstChild);
})
</script>
{% block footer %}
{% endblock %}
</html>

View file

@ -1,9 +1,5 @@
{% extends "base.html" %}
{% block head %}
<title>hallo</title>
{% endblock %}
{% block content %}
<iframe id="pdf" name="pdf" src="{{ url }}"></iframe>
{% 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 = '<a href="#"><button id="impose" onClick="impose()">impose</button></a>';
// Insert the SAVE button
const save = '<a href="#"><button id="save" onClick="printPage()" style="background-color: #66ee66;">save</button></a>';

View file

@ -19,7 +19,7 @@
<p>Below a list of the publications on the server.</p>
<ul>
{% for pub in pubs %}
<li><a href="{{ url_for('pdf',name=pub)}}">{{prettify_string(pub)}}</a></li>
<li><a href="{{ url_for('pdf',name=pub)}}">{{pub | prettify}}</a></li>
{% endfor %}
</ul>
</div>