From 43b20299733144766c49e04f0c3558e1e28364e3 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 2 May 2020 17:01:49 +0200 Subject: Feed: Add alternate links to every post. Change-Id: I2abbccabe3d53b6efade8266e11ccc9071cc1a46 --- .../eu/mulk/mulkcms2/benki/posts/PostResource.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/main/java') 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(); 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; }) -- cgit v1.2.3