summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-08-29 20:35:51 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-08-29 20:35:51 +0200
commit449afba6c208774c1d41a34671e2b4a69c857431 (patch)
treee89a3c3aea981543787d2e829815d2cca0670fee
parent66d49a3f76728945a0b8221bbcc6c54612967b9c (diff)
Remove dots after question mark titles.
Fixes: #18 Change-Id: I2915d246e2b614da69c2761864a3e5bd5300db14
-rw-r--r--src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java17
-rw-r--r--src/main/resources/templates/PostResource/postList.html2
2 files changed, 18 insertions, 1 deletions
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
index d522b1a..6264671 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/Post.java
@@ -45,6 +45,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import org.hibernate.annotations.Type;
@@ -55,6 +56,8 @@ import org.hibernate.annotations.Where;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
+ private static Pattern sentenceEnderRegex = Pattern.compile("^.*[?.]$");
+
public enum Scope {
top_level,
comment
@@ -141,6 +144,20 @@ public abstract class Post<Text extends PostText<?>> extends PanacheEntityBase {
@CheckForNull
public abstract String getUri();
+ @CheckForNull
+ public final String titleWithSentenceEnder() {
+ var title = getTitle();
+ if (title == null) {
+ return null;
+ }
+
+ if (sentenceEnderRegex.matcher(title).matches()) {
+ return title;
+ }
+
+ return title + ".";
+ }
+
public Visibility getVisibility() {
if (targets.isEmpty()) {
return Visibility.PRIVATE;
diff --git a/src/main/resources/templates/PostResource/postList.html b/src/main/resources/templates/PostResource/postList.html
index 89267a2..935b813 100644
--- a/src/main/resources/templates/PostResource/postList.html
+++ b/src/main/resources/templates/PostResource/postList.html
@@ -86,7 +86,7 @@
{/if}
<a href="{post.uri}" class="bookmark-title">
- <h2 class="bookmark-title"><span class="bookmark-symbol">🔖 </span> {post.title}</h2>.
+ <h2 class="bookmark-title"><span class="bookmark-symbol">🔖 </span> {post.titleWithSentenceEnder}</h2>
</a>
</div>
</header>