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:
2025-12-04 18:35:43 +00:00
parent f206485124
commit 449cb13dbd
2 changed files with 9 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ import json
import threading import threading
import traceback import traceback
import time import time
import datetime
import humanize
from urllib.parse import urlparse, parse_qs from urllib.parse import urlparse, parse_qs
import settings import settings
@@ -39,6 +41,11 @@ def new_id():
nid = gen_rand_id() nid = gen_rand_id()
return nid return nid
def fromnow(ts):
return humanize.naturaltime(datetime.datetime.fromtimestamp(ts))
build_folder = './build' build_folder = './build'
css_file = None css_file = None
@@ -52,6 +59,7 @@ except FileNotFoundError:
logging.warning('CSS file not found. Run webclient build.') 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 = Flask(__name__, template_folder=build_folder, static_folder=build_folder, static_url_path='')
flask_app.jinja_env.filters['fromnow'] = fromnow
cors = CORS(flask_app) cors = CORS(flask_app)
@flask_app.route('/api') @flask_app.route('/api')

View File

@@ -79,7 +79,7 @@
<div class="comment{% if level > 0 %} lined{% endif %}"> <div class="comment{% if level > 0 %} lined{% endif %}">
<div class="info"> <div class="info">
<p> <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> </p>
</div> </div>
<div class="text">{{ (comment.text | safe) if comment.text else '<p>[Empty / deleted comment]</p>' }}</div> <div class="text">{{ (comment.text | safe) if comment.text else '<p>[Empty / deleted comment]</p>' }}</div>