feat: show time ago, anchor link, and original link

This commit is contained in:
Ayo Ayco 2024-04-27 21:58:48 +02:00
parent bf98b58c90
commit 2276059d47
2 changed files with 35 additions and 25 deletions

View file

@ -119,18 +119,17 @@
grid-template-columns: auto auto; grid-template-columns: auto auto;
gap: 5px; gap: 5px;
& .anchor:hover a { & .anchor,
display: block;
}
& .anchor a { & .anchor a {
padding-top: 5px;
font-size: small;
text-align: right; text-align: right;
display: none; color: #555;
vertical-align: center;
} }
& .author a { & .author a {
display: block; display: block;
margin-bottom: 0.5em;
text-decoration: none; text-decoration: none;
color: #232323; color: #232323;
@ -212,13 +211,13 @@
<div class="card_content" id="{{ thread.id }}"> <div class="card_content" id="{{ thread.id }}">
<div class="heading"> <div class="heading">
<h3 class="author"> <h3 class="author">
<a rel="author" href="{{thread.account.url}}" <a rel="author" href="{{thread.account.url}}">{{thread.account.display_name | safe}}</a>
>{{thread.account.display_name | safe}}</a
>
</h3> </h3>
<div class="anchor"> <div class="anchor">
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + thread['id'] }}">anchor</a> <span title="{{ thread.created_at }}">{{ thread.created_at | time_ago }}</span> &middot;
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + thread['id'] }}">anchor</a> &middot;
<a href="{{ thread.url }}" target="_blank">&nearr;</a>
</div> </div>
</div> </div>
@ -251,12 +250,6 @@
</div> </div>
{% if thread.descendants is defined %} {% if thread.descendants is defined %}
<div class="meta">
<a href="{{thread.url}}" target="_blank"
>{{ thread.created_at }}</a
>
</div>
<ul> <ul>
{% for descendant in thread.descendants %} {% for descendant in thread.descendants %}
<li class="card descendant"> <li class="card descendant">
@ -279,7 +272,9 @@
</h3> </h3>
<div class="anchor"> <div class="anchor">
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + descendant['id'] }}">anchor</a> <span title="{{ descendant.created_at }}">{{ descendant.created_at | time_ago }}</span> &middot;
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + descendant['id'] }}">anchor</a>&middot;
<a href="{{ descendant.url }}" target="_blank">&nearr;</a>
</div> </div>
</div> </div>
@ -323,12 +318,6 @@
</a> </a>
{% endif %} {% endif %}
</div> </div>
<div class="meta">
<a href="{{descendant.url}}" target="_blank"
>{{ descendant.created_at }}</a
>
</div>
</div> </div>
</li> </li>

View file

@ -1,6 +1,6 @@
from flask import Blueprint, render_template from flask import Blueprint, render_template
import requests import requests
import datetime from datetime import datetime, timedelta
import markdown import markdown
import re import re
@ -23,12 +23,33 @@ attribution = {
@threads.before_request @threads.before_request
def middleware(): def middleware():
# check current year and put ange as attribution # check current year and put ange as attribution
currentDateTime = datetime.datetime.now() currentDateTime = datetime.now()
date = currentDateTime.date() date = currentDateTime.date()
year = date.strftime("%Y") year = date.strftime("%Y")
if year != attribution['year']: if year != attribution['year']:
attribution['current_year'] = year attribution['current_year'] = year
@threads.app_template_filter('time_ago')
def time_ago(date):
now = datetime.now()
date_obj = datetime.strptime(date, '%Y-%m-%dT%H:%M:%S.%fZ')
delta = now - date_obj
delta = delta - timedelta(hours=2)
days = delta.days
seconds = delta.seconds
if seconds < 3600:
return str(seconds / 60).split('.')[0] + ' minutes ago'
elif days == 0:
hours = timedelta(seconds=seconds)
return str(hours).split(':')[0] + ' hours ago'
elif days < 7:
return str(days) + ' days ago'
return date_obj.strftime('%b %d, %Y')
@threads.app_template_filter('format_date')
def format_date(date):
return date.replace('T', ' ').split('.')[0]
@threads.route('/') @threads.route('/')
def home(): def home():