feat: show time ago, anchor link, and original link
This commit is contained in:
parent
bf98b58c90
commit
2276059d47
2 changed files with 35 additions and 25 deletions
|
@ -119,18 +119,17 @@
|
|||
grid-template-columns: auto auto;
|
||||
gap: 5px;
|
||||
|
||||
& .anchor:hover a {
|
||||
display: block;
|
||||
}
|
||||
|
||||
& .anchor,
|
||||
& .anchor a {
|
||||
padding-top: 5px;
|
||||
font-size: small;
|
||||
text-align: right;
|
||||
display: none;
|
||||
color: #555;
|
||||
vertical-align: center;
|
||||
}
|
||||
|
||||
& .author a {
|
||||
display: block;
|
||||
margin-bottom: 0.5em;
|
||||
text-decoration: none;
|
||||
color: #232323;
|
||||
|
||||
|
@ -212,13 +211,13 @@
|
|||
<div class="card_content" id="{{ thread.id }}">
|
||||
<div class="heading">
|
||||
<h3 class="author">
|
||||
<a rel="author" href="{{thread.account.url}}"
|
||||
>{{thread.account.display_name | safe}}</a
|
||||
>
|
||||
<a rel="author" href="{{thread.account.url}}">{{thread.account.display_name | safe}}</a>
|
||||
</h3>
|
||||
|
||||
<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> ·
|
||||
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + thread['id'] }}">anchor</a> ·
|
||||
<a href="{{ thread.url }}" target="_blank">↗</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -251,12 +250,6 @@
|
|||
</div>
|
||||
|
||||
{% if thread.descendants is defined %}
|
||||
<div class="meta">
|
||||
<a href="{{thread.url}}" target="_blank"
|
||||
>{{ thread.created_at }}</a
|
||||
>
|
||||
</div>
|
||||
|
||||
<ul>
|
||||
{% for descendant in thread.descendants %}
|
||||
<li class="card descendant">
|
||||
|
@ -279,7 +272,9 @@
|
|||
</h3>
|
||||
|
||||
<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> ·
|
||||
<a href="{{ url_for('threads.thread', id=thread['id']) + '#' + descendant['id'] }}">anchor</a>·
|
||||
<a href="{{ descendant.url }}" target="_blank">↗</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -323,12 +318,6 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<a href="{{descendant.url}}" target="_blank"
|
||||
>{{ descendant.created_at }}</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
|
|
25
threads.py
25
threads.py
|
@ -1,6 +1,6 @@
|
|||
from flask import Blueprint, render_template
|
||||
import requests
|
||||
import datetime
|
||||
from datetime import datetime, timedelta
|
||||
import markdown
|
||||
import re
|
||||
|
||||
|
@ -23,12 +23,33 @@ attribution = {
|
|||
@threads.before_request
|
||||
def middleware():
|
||||
# check current year and put ange as attribution
|
||||
currentDateTime = datetime.datetime.now()
|
||||
currentDateTime = datetime.now()
|
||||
date = currentDateTime.date()
|
||||
year = date.strftime("%Y")
|
||||
if year != attribution['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('/')
|
||||
def home():
|
||||
|
|
Loading…
Reference in a new issue