diff --git a/apiserver/server.py b/apiserver/server.py index c8ebe1a..de25328 100644 --- a/apiserver/server.py +++ b/apiserver/server.py @@ -14,6 +14,8 @@ import json import threading import traceback import time +import datetime +import humanize from urllib.parse import urlparse, parse_qs import settings @@ -39,6 +41,11 @@ def new_id(): nid = gen_rand_id() return nid + +def fromnow(ts): + return humanize.naturaltime(datetime.datetime.fromtimestamp(ts)) + + build_folder = './build' css_file = None @@ -52,6 +59,7 @@ except FileNotFoundError: logging.warning('CSS file not found. Run webclient build.') flask_app = Flask(__name__, template_folder=build_folder, static_folder=build_folder, static_url_path='') +flask_app.jinja_env.filters['fromnow'] = fromnow cors = CORS(flask_app) @flask_app.route('/api') diff --git a/webclient/public/index.html b/webclient/public/index.html index bed25ea..79d3db7 100644 --- a/webclient/public/index.html +++ b/webclient/public/index.html @@ -79,7 +79,7 @@

- {% if comment.author == story.author %}[OP] {% endif %}{{ comment.author or '[Deleted]' }} + {% if comment.author == story.author %}[OP] {% endif %}{{ comment.author or '[Deleted]' }} | {{ comment.date | fromnow }}

{{ (comment.text | safe) if comment.text else '

[Empty / deleted comment]

' }}