Add publication date to RSS feed

This commit is contained in:
MrLetsplay 2024-02-18 14:53:33 +01:00
parent 8a67093102
commit 0aa37fd12d
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 10 additions and 2 deletions

View File

@ -215,7 +215,7 @@ public class MdBlog {
.filter(e -> e.getKey().startsWith(blogPath) && (recursive || e.getKey().length() == path.length()))
.forEach(e -> {
Post p = e.getValue();
feed.addItem(new RSSItem(p.getMetadata().title(), p.getMetadata().author(), config.link() + "/" + e.getKey().subPath(blogPath.length()), p.getMetadata().description()));
feed.addItem(new RSSItem(p.getMetadata().date(), p.getMetadata().title(), p.getMetadata().author(), config.link() + "/" + e.getKey().subPath(blogPath.length()), p.getMetadata().description()));
});
ctx.respond(HttpStatusCodes.OK_200, new RSSResponse(feed));
return;

View File

@ -1,5 +1,7 @@
package me.mrletsplay.mdblog.rss;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@ -55,6 +57,10 @@ public class RSSFeed {
Element itemEl = doc.createElement("item");
channel.appendChild(itemEl);
Element itDate = doc.createElement("pubDate");
itDate.setTextContent(DateTimeFormatter.RFC_1123_DATE_TIME.format(item.date().atZone(ZoneId.systemDefault())));
itemEl.appendChild(itDate);
Element itTitle = doc.createElement("title");
itTitle.setTextContent(item.title());
itemEl.appendChild(itTitle);

View File

@ -1,5 +1,7 @@
package me.mrletsplay.mdblog.rss;
public record RSSItem(String title, String author, String link, String description) {
import java.time.Instant;
public record RSSItem(Instant date, String title, String author, String link, String description) {
}