Add more <category> elements to RSS
authorLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Jul 2024 22:04:15 +0000 (18:04 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Jul 2024 22:04:15 +0000 (18:04 -0400)
src/jvmMain/kotlin/info/mechyrdia/lore/ViewsRss.kt

index 30268a3da68efe7b7dd63736a9643c4cd931ddf4..b16fae7b21392b685554a61138b63765a5421114 100644 (file)
@@ -58,6 +58,10 @@ suspend fun generateRecentPageEdits(): RssChannel {
        
        val mostRecentChange = pages.firstOrNull()?.stat?.updated
        
+       val mechyrdiaCategories = listOf(
+               RssCategory(domain = "https://nationstates.net", category = "Mechyrdia")
+       )
+       
        return RssChannel(
                title = "Recently Edited Factbooks | The Hour of Decision",
                link = MainDomainName,
@@ -65,9 +69,7 @@ suspend fun generateRecentPageEdits(): RssChannel {
                pubDate = mostRecentChange,
                lastBuildDate = mostRecentChange,
                ttl = 30,
-               categories = listOf(
-                       RssCategory(domain = "https://nationstates.net", category = "Mechyrdia")
-               ),
+               categories = mechyrdiaCategories,
                items = pages.mapSuspend { page ->
                        val pageLink = page.path.elements.drop(1)
                        val pageMarkup = FactbookLoader.loadFactbook(pageLink) ?: return@mapSuspend null
@@ -93,7 +95,8 @@ suspend fun generateRecentPageEdits(): RssChannel {
                                author = null,
                                comments = "$MainDomainName/lore${pageLink.joinToString(separator = "") { "/$it" }}#comments",
                                enclosure = imageEnclosure,
-                               pubDate = page.stat.updated
+                               pubDate = page.stat.updated,
+                               categories = mechyrdiaCategories,
                        )
                }.filterNotNull()
        )
@@ -104,6 +107,10 @@ suspend fun ApplicationCall.recentCommentsRssFeedGenerator(limit: Int): RssChann
        
        val validLimits = 1..100
        
+       val mechyrdiaCategories = listOf(
+               RssCategory(domain = "https://nationstates.net", category = "Mechyrdia")
+       )
+       
        if (limit !in validLimits) {
                response.status(HttpStatusCode.BadRequest)
                
@@ -114,6 +121,7 @@ suspend fun ApplicationCall.recentCommentsRssFeedGenerator(limit: Int): RssChann
                        pubDate = null,
                        lastBuildDate = Instant.now(),
                        ttl = 120,
+                       categories = mechyrdiaCategories,
                )
        }
        
@@ -141,9 +149,7 @@ suspend fun ApplicationCall.recentCommentsRssFeedGenerator(limit: Int): RssChann
                pubDate = mostRecentComment,
                lastBuildDate = mostRecentComment,
                ttl = 60,
-               categories = listOf(
-                       RssCategory(domain = "https://nationstates.net", category = "Mechyrdia")
-               ),
+               categories = mechyrdiaCategories,
                items = comments.map { comment ->
                        RssItem(
                                title = "Comment by ${comment.submittedBy.name} on $MainDomainName/${comment.submittedIn}",
@@ -152,9 +158,7 @@ suspend fun ApplicationCall.recentCommentsRssFeedGenerator(limit: Int): RssChann
                                author = null,
                                comments = "$MainDomainName/lore/${comment.submittedIn}#comment-${comment.id}",
                                pubDate = comment.lastEdit ?: comment.submittedAt,
-                               categories = listOf(
-                                       RssCategory(domain = "https://nationstates.net", category = comment.submittedBy.name)
-                               )
+                               categories = mechyrdiaCategories + RssCategory(domain = "https://nationstates.net", category = comment.submittedBy.name)
                        )
                }
        )