chaging imposition functions
This commit is contained in:
parent
e19324c220
commit
b16325d0fe
66
octomode.py
66
octomode.py
|
|
@ -26,7 +26,9 @@ 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):
|
class MarkdownRenderError(RuntimeError):
|
||||||
def __init__(self, kind, message, original):
|
def __init__(self, kind, message, original):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
|
|
@ -37,7 +39,7 @@ def get_pad_content(pad_name, ext=""):
|
||||||
if ext:
|
if ext:
|
||||||
pad_name = f'{ pad_name }{ ext }'
|
pad_name = f'{ pad_name }{ ext }'
|
||||||
|
|
||||||
print(pad_name)
|
# print(pad_name)
|
||||||
|
|
||||||
arguments = {
|
arguments = {
|
||||||
'padID' : pad_name,
|
'padID' : pad_name,
|
||||||
|
|
@ -55,7 +57,7 @@ def get_pad_content(pad_name, ext=""):
|
||||||
|
|
||||||
content = response['data']['text']
|
content = response['data']['text']
|
||||||
# print("before: " + content)
|
# print("before: " + content)
|
||||||
print( "GET PAD CONTENT" )
|
# print( "GET PAD CONTENT" )
|
||||||
for f in pad_content_filters:
|
for f in pad_content_filters:
|
||||||
content = f(content)
|
content = f(content)
|
||||||
# print("after: " + content)
|
# print("after: " + content)
|
||||||
|
|
@ -70,16 +72,13 @@ def all_pads():
|
||||||
|
|
||||||
return response
|
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():
|
def all_publications():
|
||||||
pads = all_pads()
|
pads = all_pads()
|
||||||
pubs = []
|
pubs = []
|
||||||
print(pads)
|
|
||||||
if(pads and pads['data'] and pads['data']['padIDs']):
|
if(pads and pads['data'] and pads['data']['padIDs']):
|
||||||
for pad in pads['data']['padIDs']:
|
for pad in pads['data']['padIDs']:
|
||||||
# if extension is .md add it to pubs
|
|
||||||
if pad.endswith('.md'):
|
if pad.endswith('.md'):
|
||||||
# strip the .md
|
|
||||||
name = pad.removesuffix('.md')
|
name = pad.removesuffix('.md')
|
||||||
pubs.append(name)
|
pubs.append(name)
|
||||||
return pubs
|
return pubs
|
||||||
|
|
@ -111,6 +110,10 @@ def create_pad_on_first_run(name, ext):
|
||||||
def md_to_html(md_pad_content):
|
def md_to_html(md_pad_content):
|
||||||
# Convert Markdown to HTML
|
# Convert Markdown to HTML
|
||||||
# html = markdown.markdown(md_pad_content, extensions=['meta', 'attr_list']) # attr_list does not work
|
# 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:
|
try:
|
||||||
html = pypandoc.convert_text(md_pad_content, 'html', format='md')
|
html = pypandoc.convert_text(md_pad_content, 'html', format='md')
|
||||||
except RuntimeError as exc:
|
except RuntimeError as exc:
|
||||||
|
|
@ -153,13 +156,6 @@ def get_app_root():
|
||||||
app_root = APP.config['APPLICATION_ROOT']
|
app_root = APP.config['APPLICATION_ROOT']
|
||||||
return app_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):
|
def get_meta(metadata, key, default=None):
|
||||||
return metadata.get(key, [default])[0]
|
return metadata.get(key, [default])[0]
|
||||||
|
|
||||||
|
|
@ -180,6 +176,7 @@ def clean_string(input_string):
|
||||||
snake_case_string = re.sub(r'[\s!]+', '_', input_string)
|
snake_case_string = re.sub(r'[\s!]+', '_', input_string)
|
||||||
return snake_case_string.strip('_')
|
return snake_case_string.strip('_')
|
||||||
|
|
||||||
|
@APP.template_filter('prettify') # use it in a template with | prettify
|
||||||
def prettify_string(input_string):
|
def prettify_string(input_string):
|
||||||
space_string = input_string.replace("_", " ")
|
space_string = input_string.replace("_", " ")
|
||||||
return space_string.title()
|
return space_string.title()
|
||||||
|
|
@ -202,7 +199,7 @@ def index():
|
||||||
return redirect(url_for("pad", name=name))
|
return redirect(url_for("pad", name=name))
|
||||||
else:
|
else:
|
||||||
pubs = all_publications()
|
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>/')
|
@APP.route('/<name>/')
|
||||||
def main(name):
|
def main(name):
|
||||||
|
|
@ -230,11 +227,11 @@ def pdf(name):
|
||||||
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>/impose/')
|
# @APP.route('/<name>/impose/')
|
||||||
def impose(name):
|
# def impose(name):
|
||||||
app_root = get_app_root()
|
# app_root = get_app_root()
|
||||||
url = f"{ app_root }/{name}/imposed.html"
|
# url = f"{ app_root }/{name}/imposed.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'])
|
||||||
|
|
||||||
# //////////////////
|
# //////////////////
|
||||||
# RENDERED RESOURCES
|
# RENDERED RESOURCES
|
||||||
|
|
@ -275,25 +272,26 @@ def pagedjs(name):
|
||||||
title = get_meta(metadata, 'title', 'Untitled')
|
title = get_meta(metadata, 'title', 'Untitled')
|
||||||
cover = get_meta(metadata, 'cover', None)
|
cover = get_meta(metadata, 'cover', None)
|
||||||
|
|
||||||
|
print("impose?" + str(request.args.get("impose")))
|
||||||
impose = False #request.args.get("impose") == "true"
|
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)
|
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title, cover=cover, impose=impose)
|
||||||
|
|
||||||
@APP.route('/<name>/imposed.html')
|
# @APP.route('/<name>/imposed.html')
|
||||||
def imposed(name):
|
# def imposed(name):
|
||||||
# TO GENERATE THE IMPOSED WEBPAGE
|
# # TO GENERATE THE IMPOSED WEBPAGE
|
||||||
md_pad_content = get_pad_content(name, ext='.md')
|
# md_pad_content = get_pad_content(name, ext='.md')
|
||||||
try:
|
# try:
|
||||||
html = md_to_html(md_pad_content)
|
# html = md_to_html(md_pad_content)
|
||||||
except MarkdownRenderError as exc:
|
# except MarkdownRenderError as exc:
|
||||||
return render_markdown_error(name, exc)
|
# return render_markdown_error(name, exc)
|
||||||
metadata = get_md_metadata(md_pad_content)
|
# metadata = get_md_metadata(md_pad_content)
|
||||||
lang = get_meta(metadata, 'language', 'en')
|
# lang = get_meta(metadata, 'language', 'en')
|
||||||
title = get_meta(metadata, 'title', 'Untitled')
|
# title = get_meta(metadata, 'title', 'Untitled')
|
||||||
cover = get_meta(metadata, 'cover', None)
|
# 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)
|
||||||
|
|
||||||
# //////////////////
|
# //////////////////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,14 @@
|
||||||
<html lang='en'>
|
<html lang='en'>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<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') }}">
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="wrapper">
|
<div id="nav">
|
||||||
{% block content %}
|
<h1>{{ name | prettify }} <a href="{{ url_for('index') }}"><em class="octomode">in octomode</em></a></h1>
|
||||||
{% 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="buttons">
|
<div id="buttons">
|
||||||
|
|
||||||
<a href="{{ url_for('pad', name=name) }}"><button>pad</button></a>
|
<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('pdf', name=name) }}"><button>layout</button></a>
|
||||||
|
|
||||||
<a href="{{ url_for('impose', name=name) }}"><button>impose</button></a>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
document.body.insertBefore(nav, document.body.firstChild);
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div id="wrapper">
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block head %}
|
|
||||||
<title>hallo</title>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<iframe id="pdf" name="pdf" src="{{ url }}"></iframe>
|
<iframe id="pdf" name="pdf" src="{{ url }}"></iframe>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -25,8 +21,6 @@ window.addEventListener('load', function () {
|
||||||
head.insertBefore(cssLink, head.firstChild);
|
head.insertBefore(cssLink, head.firstChild);
|
||||||
|
|
||||||
const nav = document.getElementById('buttons');
|
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
|
// Insert the SAVE button
|
||||||
const save = '<a href="#"><button id="save" onClick="printPage()" style="background-color: #66ee66;">save</button></a>';
|
const save = '<a href="#"><button id="save" onClick="printPage()" style="background-color: #66ee66;">save</button></a>';
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<p>Below a list of the publications on the server.</p>
|
<p>Below a list of the publications on the server.</p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for pub in pubs %}
|
{% 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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue