summaryrefslogtreecommitdiff
path: root/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-05-02 16:44:34 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2020-05-02 16:45:06 +0200
commite2a920026c2185f002287e1194436dd3fc438648 (patch)
tree0d6446b7d35a13193115099e754eecdc84f68f56 /src/main/java/eu
parent8001abb0147f7b976b1f46151f3ffbd3888a46e1 (diff)
Feed: Add generated titles to lazy chat messages.
Change-Id: I691cbc0a1440960a5dc8a46863d7291927ff3390
Diffstat (limited to 'src/main/java/eu')
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
index 035e47b..e5a0e7f 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java
@@ -32,6 +32,7 @@ import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.TemporalAccessor;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@@ -58,6 +59,7 @@ import javax.ws.rs.core.UriInfo;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.hibernate.Session;
import org.jboss.logging.Logger;
+import org.jsoup.Jsoup;
public abstract class PostResource {
@@ -76,6 +78,8 @@ public abstract class PostResource {
private static final int pageKeyBytes = 32;
+ private static final int AUTOTITLE_WORDS = 10;
+
protected static final JsonProvider jsonProvider = JsonProvider.provider();
@ConfigProperty(name = "mulkcms.posts.default-max-results")
@@ -315,6 +319,14 @@ public abstract class PostResource {
title.setType("text");
title.setValue(post.getTitle());
entry.setTitleEx(title);
+ } else if (post.getDescriptionHtml() != null) {
+ var title = new Content();
+ title.setType("text");
+ var words =
+ Jsoup.parse(post.getDescriptionHtml()).text().split("\\s", AUTOTITLE_WORDS);
+ var titleWords = Arrays.asList(words).subList(0, words.length - 1);
+ title.setValue(String.join(" ", titleWords) + " ...");
+ entry.setTitleEx(title);
}
if (post.getDescriptionHtml() != null) {