allow pages to specify different templates

This commit is contained in:
Brian S. Stephan 2021-04-30 19:32:06 -05:00
parent f4beb15a3b
commit e8377adcf5
5 changed files with 62 additions and 1 deletions

View File

@ -58,7 +58,9 @@ def display_page(path):
page_title = f'{page_name} - {app.config["TITLE_SUFFIX"]}' if page_name else app.config['TITLE_SUFFIX']
logger.debug("title (potentially derived): %s", page_title)
return render('base.html', title=page_title, description=get_meta_str(md, 'description'),
template = get_meta_str(md, 'template') if md.Meta.get('template') else 'base.html'
return render(template, title=page_title, description=get_meta_str(md, 'description'),
image=get_meta_str(md, 'image'), base_url=request.base_url, content=content,
navs=parent_navs, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'))
else:

View File

@ -19,6 +19,14 @@ body {
margin-right: auto;
}
.site-wrap-wide {
max-width: 95pc;
min-height: 100vh;
margin: 0;
margin-left: auto;
margin-right: auto;
}
h1 {
font-size: 2em;
}

View File

@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<title>{{ title }}</title>
{% if title %}<meta property="og:title" content="{{ title }}">{% endif %}
{% if description %}<meta property="og:description" content="{{ description }}">{% endif %}
{% if image %}<meta property="og:image" content="{{ image }}">{% endif %}
<meta property="og:url" content="{{ base_url }}">
<meta name="twitter:card" content="summary_large_image">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ url_for('static', filename=user_style) }}">
<link rel="icon" href="{% if config.FAVICON %}{{ config.FAVICON }}{% else %}{{ url_for('static', filename='img/favicon.png') }}{% endif %}">
<div class="wide-site-wrap">
{% block header %}
<div class="header">
<div class="nav">
{% for nav in navs %}
<a href="{{ nav.1 }}">{{ nav.0 }}</a>
{% if not loop.last %} &raquo; {% endif %}
{% endfor %}
</div>
<div class="styles">
<a href="?style=dark">[dark]</a>
<a href="?style=light">[light]</a>
<a href="?style=plain">[plain]</a>
</div>
</div>
{% endblock %}
{% block body %}
<div class="content">
{{ content }}
</div>
<footer>
<i>Last modified: {{ mtime }}</i>
</footer>
{% endblock %}
</div>
</html>

View File

@ -193,3 +193,13 @@ def test_setting_selected_style_includes_cookie(client):
assert b'dark.css' in response.data
assert b'light.css' not in response.data
assert style_cookie.value == 'dark'
def test_pages_can_supply_alternate_templates(client):
"""Test that pages can supply templates other than the default."""
response = client.get('/')
assert b'class="site-wrap"' in response.data
assert b'class="wide-site-wrap"' not in response.data
response = client.get('/custom-template')
assert b'class="site-wrap"' not in response.data
assert b'class="wide-site-wrap"' in response.data

View File

@ -0,0 +1,3 @@
Template: base-wide.html
testttttttttt