support multiple images per post

This commit is contained in:
2025-09-20 12:14:19 +02:00
parent 60dfe90152
commit 41133edaca
3 changed files with 36 additions and 10 deletions
@@ -35,7 +35,7 @@ public class FediServlet extends HttpServlet {
throws ServletException, IOException { throws ServletException, IOException {
try { try {
final JSONLoader loader = new JSONLoader("mastodon.social", "Mastodon"); final JSONLoader loader = new JSONLoader("mastodon.social", "doppelkeks");
final VelocityContext context = new VelocityContext(); final VelocityContext context = new VelocityContext();
context.put("profile", loader.loadProfile()); context.put("profile", loader.loadProfile());
context.put("pinned", loader.loadPinned()); context.put("pinned", loader.loadPinned());
@@ -20,12 +20,12 @@ public class JSONLoader implements Serializable {
private final String instance; private final String instance;
private final String account; private final String account;
private int id; private long id;
public JSONLoader(String instance, String account) { public JSONLoader(String instance, String account) {
this.instance = instance; this.instance = instance;
this.account = account; this.account = account;
this.id = -1; this.id = -1L;
} }
public JSONObject loadProfile() throws IOException, URISyntaxException { public JSONObject loadProfile() throws IOException, URISyntaxException {
@@ -40,7 +40,7 @@ public class JSONLoader implements Serializable {
content.append(line); content.append(line);
} }
final JSONObject data = new JSONObject(content.toString()); final JSONObject data = new JSONObject(content.toString());
id = data.getInt("id"); id = data.getLong("id");
return data; return data;
} }
+32 -6
View File
@@ -300,6 +300,7 @@
--> -->
<div id="posts" class="posts"> <div id="posts" class="posts">
#foreach( $post in $pinned ) #foreach( $post in $pinned )
#set ( $image_class = 'single' )
<div class="post"> <div class="post">
<div class="boost-indicator">📌 Angeheftet</div> <div class="boost-indicator">📌 Angeheftet</div>
<div class="post-header"> <div class="post-header">
@@ -311,11 +312,19 @@
</div> </div>
<div class="post-content">$post.content</div> <div class="post-content">$post.content</div>
#if( $post.media_attachments.length > 0 ) #if( $post.media_attachments.length > 0 )
#if( $post.media_attachments.length > 1 )
#set ( $image_class = 'double' )
#end
#if( $post.media_attachments.length > 2 )
#set ( $image_class = 'multiple' )
#end
<div class="post-media"> <div class="post-media">
<div class="media-grid single"> <div class="media-grid $image_class">
#foreach( $media_item in $post.media_attachments )
<div class="media-item"> <div class="media-item">
<img src="$post.media_attachments[0].preview_url" alt="$post.media_attachments[0].description" onclick="window.open('$post.media_attachments[0].url', '_blank')"> <img src="$media_item.preview_url" alt="$media_item.description" onclick="window.open('$media_item.url', '_blank')">
</div> </div>
#end
</div> </div>
</div> </div>
#end #end
@@ -327,8 +336,15 @@
</div> </div>
#end #end
#foreach( $post in $timeline ) #foreach( $post in $timeline )
#set ( $image_class = 'single' )
<div class="post"> <div class="post">
#if( $post.reblog.account ) #if( $post.reblog.account )
#if( $post.reblog.media_attachments.length > 1 )
#set ( $image_class = 'double' )
#end
#if( $post.reblog.media_attachments.length > 2 )
#set ( $image_class = 'multiple' )
#end
<div class="boost-indicator">🔄 $post.account.display_name hat geteilt</div> <div class="boost-indicator">🔄 $post.account.display_name hat geteilt</div>
<div class="post-header"> <div class="post-header">
<img class="post-avatar" src="$post.reblog.account.avatar" alt="Avatar"> <img class="post-avatar" src="$post.reblog.account.avatar" alt="Avatar">
@@ -340,14 +356,22 @@
<div class="post-content">$post.reblog.content</div> <div class="post-content">$post.reblog.content</div>
#if( $post.reblog.media_attachments.length > 0 ) #if( $post.reblog.media_attachments.length > 0 )
<div class="post-media"> <div class="post-media">
<div class="media-grid single"> <div class="media-grid $image_class">
#foreach( $media_item in $post.reblog.media_attachments )
<div class="media-item"> <div class="media-item">
<img src="$post.reblog.media_attachments[0].preview_url" alt="$post.reblog.media_attachments[0].description" onclick="window.open('$post.reblog.media_attachments[0].url', '_blank')"> <img src="$media_item.preview_url" alt="$media_item.description" onclick="window.open('$media_item.url', '_blank')">
</div> </div>
#end
</div> </div>
</div> </div>
#end #end
#else #else
#if( $post.media_attachments.length > 1 )
#set ( $image_class = 'double' )
#end
#if( $post.media_attachments.length > 2 )
#set ( $image_class = 'multiple' )
#end
<div class="post-header"> <div class="post-header">
<img class="post-avatar" src="$post.account.avatar" alt="Avatar"> <img class="post-avatar" src="$post.account.avatar" alt="Avatar">
<div class="post-user"> <div class="post-user">
@@ -358,10 +382,12 @@
<div class="post-content">$post.content</div> <div class="post-content">$post.content</div>
#if( $post.media_attachments.length > 0 ) #if( $post.media_attachments.length > 0 )
<div class="post-media"> <div class="post-media">
<div class="media-grid single"> <div class="media-grid $image_class">
#foreach( $media_item in $post.media_attachments )
<div class="media-item"> <div class="media-item">
<img src="$post.media_attachments[0].preview_url" alt="$post.media_attachments[0].description" onclick="window.open('$post.media_attachments[0].url', '_blank')"> <img src="$media_item.preview_url" alt="$media_item.description" onclick="window.open('$media_item.url', '_blank')">
</div> </div>
#end
</div> </div>
</div> </div>
#end #end