From: David ‘Bombe’ Roden Date: Mon, 17 Sep 2012 05:04:11 +0000 (+0200) Subject: Abbreviate excerpts on the last space. X-Git-Tag: 0.8.3^2~10 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=358b2cc71703c3cb12355f9a109e0b484ed8c1ba;p=Sone.git Abbreviate excerpts on the last space. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 1936656..75eff8b 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -249,7 +249,13 @@ public class ParserFilter implements Filter { for (Part part : parts) { excerpt.append(part.getText()); if (excerpt.length() > 20) { - excerpt.setLength(20); + int lastSpace = excerpt.lastIndexOf(" ", 20); + if (lastSpace > -1) { + excerpt.setLength(lastSpace); + } else { + excerpt.setLength(20); + } + excerpt.append("…"); break; } }