Abbreviate excerpts on the last space.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Sep 2012 05:04:11 +0000 (07:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Sep 2012 05:04:11 +0000 (07:04 +0200)
src/main/java/net/pterodactylus/sone/template/ParserFilter.java

index 1936656..75eff8b 100644 (file)
@@ -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;
                                }
                        }