20 lines
819 B
Java
20 lines
819 B
Java
package eu.m724.blog.data;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.List;
|
|
|
|
public class Feed {
|
|
public static String generateRss(Site site, List<Post> posts) {
|
|
var content = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><rss version=\"2.0\">";
|
|
content += "<channel><title>%s</title><link>%s</link>".formatted(site.name(), site.baseUrl());
|
|
|
|
var formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz");
|
|
for (var post : posts) {
|
|
content += "<item><title>%s</title><link>%s/post/%s.html</link><description>%s</description><pubDate>%s</pubDate></item>".formatted(post.title(), site.baseUrl(), post.slug(), post.summary(), post.createdAt().format(formatter));
|
|
}
|
|
|
|
content += "</channel></rss>";
|
|
|
|
return content;
|
|
}
|
|
}
|