in generator/src/main/groovy/generator/SiteGenerator.groovy [289:344]
private void renderBlogFeed(Map<String, Document> blogList, String baseDir) {
def sorted = blogList.sort { e1, e2 -> e2.value.revisionInfo.date <=> e1.value.revisionInfo.date }
def base = "http://groovy.apache.org/$baseDir"
def feedDir = new File(outputDir, baseDir)
feedDir.mkdirs()
def feedFile = new File(feedDir, 'feed.atom')
def builder = new StreamingMarkupBuilder()
builder.encoding = 'UTF-8'
// Use the most recent update date for the feed-level 'updated' element
def mostRecentUpdate = sorted.collect { it.value.attributes.updated ?: it.value.revisionInfo.date }.max()
def formatDateToRFC3339 = { dateStr ->
try {
// Parse the date string to a ZonedDateTime and then format it to RFC 3339
def parsedDate = ZonedDateTime.parse(dateStr)
DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(parsedDate)
} catch (DateTimeParseException e) {
println "Invalid date format: $dateStr. Using fallback."
return "1970-01-01T00:00:00Z" // Return the fallback date
}
}
def blogs = builder.bind {
mkp.xmlDeclaration()
namespaces << ['': 'http://www.w3.org/2005/Atom']
feed {
title('Groovy Blogs')
subtitle('News and stories from the Groovy Ecosystem')
link(href: base)
link(href: "$base/feed.atom", rel: 'self')
id(base)
updated(formatDateToRFC3339(mostRecentUpdate)) // Format to RFC 3339
sorted.each { k, v ->
def publishDate = v.revisionInfo.date
def updateDate = v.attributes.updated ?: v.revisionInfo.date
// Atom allows multiple author tags but not all readers support that, so merge them
def authorName = v.authors ? v.authors*.fullName.join(', ') : null
entry {
id("$base/$k")
if (authorName) {
author {
name(authorName)
}
}
title(v.structuredDoctitle.combined, type: "html")
link(href: "$base/$k")
updated(formatDateToRFC3339(updateDate)) // Format to RFC 3339
published(formatDateToRFC3339(publishDate)) // Format to RFC 3339
summary(v.attributes.description ?: '', type: "html")
}
}
}
}
feedFile.text = XmlUtil.serialize(blogs)
}