forked from tanner/qotnews
feat: Add relative timestamps and permalinks to comments
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
<div class="comment{% if level > 0 %} lined{% endif %}">
|
||||
<div class="info">
|
||||
<p>
|
||||
{% if comment.author == story.author %}[OP] {% endif %}{{ comment.author or '[Deleted]' }}
|
||||
{% if comment.author == story.author %}[OP] {% endif %}{{ comment.author or '[Deleted]' }} | <a href="#{{ comment.author }}{{ comment.date }}" id="{{ comment.author }}{{ comment.date }}">{{ comment.date | fromnow }}</a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="text">{{ (comment.text | safe) if comment.text else '<p>[Empty / deleted comment]</p>' }}</div>
|
||||
|
||||
Reference in New Issue
Block a user