include post date as link
This commit is contained in:
@@ -46,6 +46,8 @@ public class FediServlet extends HttpServlet {
|
||||
context.put("profile", loader.loadProfile());
|
||||
context.put("pinned", loader.loadPinned());
|
||||
context.put("timeline", loader.loadTimeline());
|
||||
context.put("dateformatter", new PostDateFormatter());
|
||||
|
||||
final Template template = velocityEngine.getTemplate("/templates/profil.vm");
|
||||
response.setContentType("text/html;charset=UTF-8");
|
||||
try (PrintWriter writer = response.getWriter()) {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package de.jalin.fedipage;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class PostDateFormatter {
|
||||
|
||||
final SimpleDateFormat dfTimestamp;
|
||||
final SimpleDateFormat dfEuropean;
|
||||
|
||||
public PostDateFormatter() {
|
||||
dfTimestamp = new SimpleDateFormat("yyyy-MM-dd");
|
||||
dfEuropean = new SimpleDateFormat("dd.MM.yyyy");
|
||||
}
|
||||
|
||||
public String format(final String timestamp) {
|
||||
if (timestamp == null) {
|
||||
return "unbekannt";
|
||||
}
|
||||
if (timestamp.length() < 10) {
|
||||
return timestamp;
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
if (timestamp.startsWith(dfTimestamp.format(new Date(now)))) {
|
||||
return "heute";
|
||||
}
|
||||
if (timestamp.startsWith(dfTimestamp.format(new Date(now - (24*60*60*1000L))))) {
|
||||
return "gestern";
|
||||
}
|
||||
try {
|
||||
final Date date = dfTimestamp.parse(timestamp.substring(0, 10));
|
||||
return dfEuropean.format(date);
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
return timestamp.substring(0, 10);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,6 +156,12 @@
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.post-date a {
|
||||
color: #9baec8;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.post-content {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
@@ -301,6 +307,7 @@
|
||||
<div id="posts" class="posts">
|
||||
#foreach( $post in $pinned )
|
||||
#set ( $image_class = 'single' )
|
||||
#set ( $post_date = $dateformatter.format( $post.created_at ) )
|
||||
<div class="post">
|
||||
<div class="boost-indicator">📌 Angeheftet</div>
|
||||
<div class="post-header">
|
||||
@@ -309,6 +316,7 @@
|
||||
<div class="post-display-name">$post.account.display_name</div>
|
||||
<div class="post-username"><a href="$post.account.url">@$post.account.acct</a></div>
|
||||
</div>
|
||||
<div class="post-date"><a href="$post.url" target="_blank">$post_date</a></div>
|
||||
</div>
|
||||
<div class="post-content">$post.content</div>
|
||||
#if( $post.media_attachments.length > 0 )
|
||||
@@ -339,6 +347,7 @@
|
||||
#set ( $image_class = 'single' )
|
||||
<div class="post">
|
||||
#if( $post.reblog.account )
|
||||
#set ( $post_date = $dateformatter.format( $post.reblog.created_at ) )
|
||||
#if( $post.reblog.media_attachments.length > 1 )
|
||||
#set ( $image_class = 'double' )
|
||||
#end
|
||||
@@ -352,6 +361,7 @@
|
||||
<div class="post-display-name">$post.reblog.account.display_name</div>
|
||||
<div class="post-username"><a href="$post.reblog.account.url">@$post.reblog.account.acct</a></div>
|
||||
</div>
|
||||
<div class="post-date"><a href="$post.reblog.url" target="_blank">$post_date</a></div>
|
||||
</div>
|
||||
<div class="post-content">$post.reblog.content</div>
|
||||
#if( $post.reblog.media_attachments.length > 0 )
|
||||
@@ -366,6 +376,7 @@
|
||||
</div>
|
||||
#end
|
||||
#else
|
||||
#set ( $post_date = $dateformatter.format( $post.created_at ) )
|
||||
#if( $post.media_attachments.length > 1 )
|
||||
#set ( $image_class = 'double' )
|
||||
#end
|
||||
@@ -378,6 +389,7 @@
|
||||
<div class="post-display-name">$post.account.display_name</div>
|
||||
<div class="post-username"><a href="$post.account.url">@$post.account.acct</a></div>
|
||||
</div>
|
||||
<div class="post-date"><a href="$post.url" target="_blank">$post_date</a></div>
|
||||
</div>
|
||||
<div class="post-content">$post.content</div>
|
||||
#if( $post.media_attachments.length > 0 )
|
||||
|
||||
Reference in New Issue
Block a user