Add lore intro page
authorLanius Trolling <lanius@laniustrolling.dev>
Thu, 27 Jul 2023 14:04:28 +0000 (10:04 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Thu, 27 Jul 2023 14:04:28 +0000 (10:04 -0400)
src/main/kotlin/info/mechyrdia/Factbooks.kt
src/main/kotlin/info/mechyrdia/lore/view_nav.kt
src/main/kotlin/info/mechyrdia/lore/views_lore.kt

index cd73f1b5d9e17511c10adf8baf1e6dfcd7261b7e..867d0df26dd3a74de4e208b520c89b3a99ef7d4d 100644 (file)
@@ -129,7 +129,7 @@ fun Application.factbooks() {
        
        routing {
                get("/") {
-                       redirect("/lore")
+                       call.respondHtml(HttpStatusCode.OK, call.loreIntroPage())
                }
                
                // Factbooks and assets
index d6c8a322e5f3182c1a6f0214f37d726d32c2869c..9ab9faba9ee016372899b16e7c95ab62db067374 100644 (file)
@@ -13,6 +13,7 @@ import kotlin.collections.component2
 import kotlin.collections.set
 
 suspend fun ApplicationCall.standardNavBar(path: List<String>? = null) = listOf(
+       NavLink("/", "Intro"),
        NavLink("/lore", "Lore Index")
 ) + path?.let { pathParts ->
        pathParts.dropLast(1).mapIndexed { i, part ->
index 4e58a4e775c1db7df1db04e3d0ebb320454d89e4..c954c1b344f067c884434c3b2cc06dd7f4bfdc11 100644 (file)
@@ -10,6 +10,41 @@ import kotlinx.coroutines.flow.toList
 import kotlinx.html.*
 import java.io.File
 
+private const val INTRO_TITLE = "Welcome to Mechyrdia"
+private const val INTRO_COMMENTS_PATH = "/"
+
+suspend fun ApplicationCall.loreIntroPage(): HTML.() -> Unit {
+       val totalsData = processGuestbook()
+       
+       val (canCommentAs, comments) = coroutineScope {
+               val canCommentAs = async { currentNation() }
+               val comments = async {
+                       CommentRenderData(Comment.getCommentsIn(INTRO_COMMENTS_PATH).toList(), nationCache)
+               }
+               
+               canCommentAs.await() to comments.await()
+       }
+       
+       val sidebar = PageNavSidebar(
+               listOf(
+                       NavLink("#page-top", INTRO_TITLE, aClasses = "left"),
+                       NavLink("#comments", "Comments", aClasses = "left")
+               )
+       )
+       
+       val htmlFile = File(Configuration.CurrentConfiguration.articleDir).parentFile.combineSafe("intro.html")
+       val fileHtml = htmlFile.readText()
+       
+       return page(INTRO_TITLE, standardNavBar(), sidebar) {
+               section {
+                       a { id = "page-top" }
+                       unsafe { raw(fileHtml) }
+               }
+               
+               finalSection(INTRO_COMMENTS_PATH, canCommentAs, comments, totalsData)
+       }
+}
+
 suspend fun ApplicationCall.loreArticlePage(): HTML.() -> Unit {
        val totalsData = processGuestbook()