From e2a920026c2185f002287e1194436dd3fc438648 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 2 May 2020 16:44:34 +0200 Subject: Feed: Add generated titles to lazy chat messages. Change-Id: I691cbc0a1440960a5dc8a46863d7291927ff3390 --- src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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) { -- cgit v1.2.3