Feed: Add alternate links to every post.
Change-Id: I2abbccabe3d53b6efade8266e11ccc9071cc1a46
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 e5a0e7f..580f8bc 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.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.TemporalAccessor;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
@@ -330,18 +331,31 @@
}
if (post.getDescriptionHtml() != null) {
- var summary = new Content();
- summary.setType("html");
- summary.setValue(post.getDescriptionHtml());
- entry.setSummary(summary);
+ var description = new Content();
+ description.setType("html");
+ description.setValue(post.getDescriptionHtml());
+ if (post.getUri() != null) {
+ entry.setSummary(description);
+ } else {
+ entry.setContents(List.of(description));
+ }
}
+ var alternateLinks = new ArrayList<Link>();
if (post.getUri() != null) {
- var link = new Link();
- link.setHref(post.getUri());
- link.setRel("alternate");
- entry.setAlternateLinks(List.of(link));
+ var postUriLink = new Link();
+ postUriLink.setRel("alternate");
+ postUriLink.setHref(post.getUri());
+ alternateLinks.add(postUriLink);
+ } else {
+ var postSelfHref =
+ uri.resolve(URI.create(String.format("/posts/%d", post.id))).toString();
+ var postSelfLink = new Link();
+ postSelfLink.setRel("alternate");
+ postSelfLink.setHref(postSelfHref);
+ alternateLinks.add(postSelfLink);
}
+ entry.setAlternateLinks(alternateLinks);
return entry;
})