Refactor repeated code
authorLanius Trolling <lanius@laniustrolling.dev>
Thu, 28 Dec 2023 17:43:31 +0000 (12:43 -0500)
committerLanius Trolling <lanius@laniustrolling.dev>
Thu, 28 Dec 2023 17:43:31 +0000 (12:43 -0500)
src/jvmMain/kotlin/info/mechyrdia/lore/article_listing.kt
src/jvmMain/kotlin/info/mechyrdia/lore/views_lore.kt

index bfb758506371da64b47596c02a9fe868883ed82d..5bac26d5fab5d45670dcf7a618e9e87e7b5e30d7 100644 (file)
@@ -22,10 +22,19 @@ fun File.toArticleNode(): ArticleNode = ArticleNode(
                .sortedBy { it.subNodes.isEmpty() }
 )
 
+private val String.isViewable: Boolean
+       get() = Configuration.CurrentConfiguration.isDevMode || !(endsWith(".wip") || endsWith(".old"))
+
+val ArticleNode.isViewable: Boolean
+       get() = name.isViewable
+
+val File.isViewable: Boolean
+       get() = name.isViewable
+
 fun List<ArticleNode>.renderInto(list: UL, base: String? = null) {
        val prefix by lazy(LazyThreadSafetyMode.NONE) { base?.let { "$it/" } ?: "" }
        for (node in this) {
-               if (Configuration.CurrentConfiguration.isDevMode || !(node.name.endsWith(".wip") || node.name.endsWith(".old")))
+               if (node.isViewable)
                        list.li {
                                a(href = "/lore/$prefix${node.name}") { +node.name }
                                if (node.subNodes.isNotEmpty())
index 9a32057d0f8bc39572a39fe19eb521d45778ea0f..e594946dc8136e24796410ac3a5a22247f4d82a0 100644 (file)
@@ -56,7 +56,7 @@ suspend fun ApplicationCall.loreArticlePage(): HTML.() -> Unit {
                canCommentAs.await() to comments.await()
        }
        
-       val isValid = pageFile.exists() && (Configuration.CurrentConfiguration.isDevMode || !(pageFile.name.endsWith(".wip") || pageFile.name.endsWith(".old")))
+       val isValid = pageFile.exists() && pageFile.isViewable
        
        if (isValid) {
                if (pageFile.isDirectory) {