add page modified time to the template

This commit is contained in:
2020-03-07 15:39:12 -06:00
parent 75f8488fc3
commit 04145e92f8
3 changed files with 16 additions and 1 deletions

View File

@@ -1,8 +1,11 @@
"""General page functionality."""
import datetime
import logging
import os
import markdown
from flask import Blueprint, Markup, abort, current_app as app, render_template
from tzlocal import get_localzone
logger = logging.getLogger(__name__)
@@ -19,6 +22,7 @@ def display_page(path):
try:
with app.open_instance_resource(resolved_path, 'r') as entry_file:
logger.debug("file '%s' found", resolved_path)
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(entry_file.name), get_localzone())
entry = entry_file.read()
except FileNotFoundError:
logger.warning("requested path '%s' (resolved path '%s') not found!", path, resolved_path)
@@ -27,7 +31,7 @@ def display_page(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)
return render_template('base.html', title=title, content=content, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'))
def page_file_resolver(path):

View File

@@ -3,3 +3,6 @@
<section class="content">
{{ content }}
</section>
<footer>
<i>Last modified: {{ mtime }}</i>
</footer>