adding application_root urls + default metadata

This commit is contained in:
manetta 2022-03-11 18:00:22 +01:00
parent f7105a30bf
commit 44818d981c
5 changed files with 22 additions and 17 deletions

View File

@ -120,23 +120,23 @@ def main(name):
def pad(name):
pad_name = f'{ name }.md'
url = os.path.join(APP.config['PAD_URL'], pad_name)
return render_template('iframe.html', url=url, name=name.strip())
return render_template('iframe.html', url=url, name=name.strip(), application_root=APP.config["APPLICATION_ROOT"])
@APP.route('/<name>/stylesheet/')
def stylesheet(name):
pad_name = f'{ name }.css'
url = os.path.join(APP.config['PAD_URL'], pad_name)
return render_template('iframe.html', url=url, name=name.strip())
return render_template('iframe.html', url=url, name=name.strip(), application_root=APP.config["APPLICATION_ROOT"])
@APP.route('/<name>/html/')
def html(name):
path = os.path.join(f'/{ name }/', 'preview.html')
return render_template('iframe.html', url=path, name=name.strip())
return render_template('iframe.html', url=path, name=name.strip(), application_root=APP.config["APPLICATION_ROOT"])
@APP.route('/<name>/pdf/')
def pdf(name):
path = os.path.join(f'/{ name }/', 'pagedjs.html')
return render_template('pdf.html', url=path, name=name.strip())
return render_template('pdf.html', url=path, name=name.strip(), application_root=APP.config["APPLICATION_ROOT"])
# //////////////////
# RENDERED RESOURCES
@ -156,10 +156,14 @@ def preview(name):
md_pad_content = get_pad_content(name, ext='.md')
html = md_to_html(md_pad_content)
metadata = get_md_metadata(md_pad_content)
lang = metadata['language'][0]
title = metadata['title'][0]
if metadata:
lang = metadata['language'][0]
title = metadata['title'][0]
else:
lang = "en"
title = "No title"
return render_template('preview.html', name=name.strip(), pad_content=html, lang=lang, title=title)
return render_template('preview.html', name=name.strip(), pad_content=html, lang=lang, title=title, application_root=APP.config["APPLICATION_ROOT"])
@APP.route('/<name>/pagedjs.html')
def pagedjs(name):
@ -170,7 +174,7 @@ def pagedjs(name):
lang = metadata['language'][0]
title = metadata['title'][0]
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, application_root=APP.config["APPLICATION_ROOT"])
# //////////////////

View File

@ -20,14 +20,15 @@ window.addEventListener('load', function () {
const nav = document.createElement('div');
nav.id = 'nav';
const name = '{{ name }}';
const application_root = '{{ application_root }}';
nav.innerHTML = `
<h1>${ name } <a href="/"><em class="octomode">in octomode</em></a></h1>
<div id="buttons">
<a href="/${ name }/pad/"><button>pad</button></a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/${ name }.md">
<a href="/${ name }/stylesheet/"><button>stylesheet</button></a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/${ name }.css">
<a href="/${ name }/html/"><button>html</button></a>
<a href="/${ name }/pdf/"><button>pdf</button></a>
<a href="${ application_root }${ name }/pad/"><button>pad</button></a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/${ name }.md">
<a href="${ application_root }${ name }/stylesheet/"><button>stylesheet</button></a>: <input type="text" name="pad" value="https://pad.vvvvvvaria.org/${ name }.css">
<a href="${ application_root }${ name }/html/"><button>html</button></a>
<a href="${ application_root }${ name }/pdf/"><button>pdf</button></a>
</div>`;
document.body.insertBefore(nav, document.body.firstChild);

View File

@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/static/paged.polyfill.js" type="text/javascript"></script>
<link href="/static/pagedjs.css" rel="stylesheet" type="text/css" media="screen">
<link href="/{{ name }}/stylesheet.css" rel="stylesheet" type="text/css" media="print">
<script src="{{ application_root }}static/paged.polyfill.js" type="text/javascript"></script>
<link href="{{ application_root }}static/pagedjs.css" rel="stylesheet" type="text/css" media="screen">
<link href="{{ application_root }}{{ name }}/stylesheet.css" rel="stylesheet" type="text/css" media="print">
<title>{{ title }}</title>
</head>
<body>

View File

@ -16,7 +16,7 @@ window.addEventListener('load', function () {
// Load the main.css again, to load the stylesheet for the nav
var cssLink = document.createElement('link');
cssLink.rel = 'stylesheet';
cssLink.href = '/static/main.css';
cssLink.href = '{{ application_root }}/static/main.css';
var head = document.getElementsByTagName('head')[0];
head.insertBefore(cssLink, head.firstChild);

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/{{ name }}/stylesheet.css" rel="stylesheet" type="text/css" media="screen">
<link href="{{ application_root }}/{{ name }}/stylesheet.css" rel="stylesheet" type="text/css" media="screen">
<title>{{ title }}</title>
</head>
<body>