diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2020-05-02 17:01:49 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2020-05-02 17:11:47 +0200 |
commit | 43b20299733144766c49e04f0c3558e1e28364e3 (patch) | |
tree | cb021aee34c1b37b231437ac5e18b25abd2b90fe /src | |
parent | 1fdf09bb7ec5570a42c84c54262e666c6503e269 (diff) |
Feed: Add alternate links to every post.
Change-Id: I2abbccabe3d53b6efade8266e11ccc9071cc1a46
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java | 30 |
1 files changed, 22 insertions, 8 deletions
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.ZoneOffset; 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 @@ public abstract class PostResource { } 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; }) |