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:
parent
0118eb2994
commit
1f420eab30
@ -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):
|
||||
|
5
incorporealcms/templates/base.html
Normal file
5
incorporealcms/templates/base.html
Normal file
@ -0,0 +1,5 @@
|
||||
<!doctype html>
|
||||
<title>{{ title }}{% if title %} - {% endif %}incorporeal.org</title>
|
||||
<section class="content">
|
||||
{{ content }}
|
||||
</section>
|
@ -12,6 +12,7 @@ flask==1.1.1 # via -r requirements/requirements.in
|
||||
importlib-metadata==1.5.0 # via pluggy, pytest
|
||||
itsdangerous==1.1.0 # via flask
|
||||
jinja2==2.11.1 # via flask
|
||||
markdown==3.2.1 # via -r requirements/requirements.in
|
||||
markupsafe==1.1.1 # via jinja2
|
||||
mccabe==0.6.1 # via flake8
|
||||
more-itertools==8.2.0 # via pytest
|
||||
@ -28,3 +29,6 @@ versioneer==0.18 # via -r requirements/requirements-dev.in
|
||||
wcwidth==0.1.8 # via pytest
|
||||
werkzeug==1.0.0 # via flask
|
||||
zipp==3.1.0 # via importlib-metadata
|
||||
|
||||
# The following packages are considered to be unsafe in a requirements file:
|
||||
# setuptools
|
||||
|
@ -1 +1,2 @@
|
||||
Flask # general purpose web service and web server stuff
|
||||
Markdown # markdown rendering in templates
|
||||
|
@ -8,5 +8,9 @@ click==7.0 # via flask
|
||||
flask==1.1.1 # via -r requirements/requirements.in
|
||||
itsdangerous==1.1.0 # via flask
|
||||
jinja2==2.11.1 # via flask
|
||||
markdown==3.2.1 # via -r requirements/requirements.in
|
||||
markupsafe==1.1.1 # via jinja2
|
||||
werkzeug==1.0.0 # via flask
|
||||
|
||||
# The following packages are considered to be unsafe in a requirements file:
|
||||
# setuptools
|
||||
|
@ -1,3 +1,5 @@
|
||||
Title: Index
|
||||
|
||||
# test index
|
||||
|
||||
this is some test content
|
||||
|
1
tests/instance/journal/no-title.md
Normal file
1
tests/instance/journal/no-title.md
Normal file
@ -0,0 +1 @@
|
||||
# this page doesn't have a title!
|
@ -17,8 +17,22 @@ def test_journal_file_resolver_other_requests_fine():
|
||||
def test_journal_file_that_exists(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<h1>test index</h1>' in response.data
|
||||
|
||||
|
||||
def test_journal_file_that_doesnt_exist(client):
|
||||
response = client.get('/ohuesthaoeusth')
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_journal_file_with_title_metadata(client):
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>Index - incorporeal.org</title>' in response.data
|
||||
|
||||
|
||||
def test_journal_file_without_title_metadata(client):
|
||||
response = client.get('/no-title')
|
||||
assert response.status_code == 200
|
||||
assert b'<title>incorporeal.org</title>' in response.data
|
||||
assert b'<h1>this page doesn\'t have a title!</h1>' in response.data
|
||||
|
Loading…
Reference in New Issue
Block a user