journal: render markdown content + title metadata

this has a really basic template and whatnot at the moment, so
styling/etc isn't done, but this is maybe the last major piece before I
could actually see pushing this onto the site
This commit is contained in:
2020-03-07 11:54:26 -06:00
parent 0118eb2994
commit 1f420eab30
8 changed files with 39 additions and 4 deletions

View File

@@ -1,11 +1,13 @@
"""Journal functionality."""
import logging
from flask import Blueprint, abort, current_app as app
import markdown
from flask import Blueprint, Markup, abort, current_app as app, render_template
logger = logging.getLogger(__name__)
bp = Blueprint('journal', __name__, url_prefix='/')
md = markdown.Markdown(extensions=['meta'])
@bp.route('/', defaults={'path': 'index'})
@@ -17,13 +19,15 @@ def display_journal_entry(path):
try:
with app.open_instance_resource(resolved_path, 'r') as entry_file:
logger.debug("file '%s' found", resolved_path)
entry = entry_file.read()
except FileNotFoundError:
logger.warning("requested path '%s' (resolved path '%s') not found!", path, resolved_path)
abort(404)
else:
return "OK"
return resolved_path
content = Markup(md.convert(entry))
logger.debug("file metadata: %s", md.Meta)
title = " ".join(md.Meta.get('title')) if md.Meta.get('title') else ""
return render_template('base.html', title=title, content=content)
def journal_file_resolver(path):

View File

@@ -0,0 +1,5 @@
<!doctype html>
<title>{{ title }}{% if title %} - {% endif %}incorporeal.org</title>
<section class="content">
{{ content }}
</section>