From: Lanius Trolling Date: Thu, 28 Dec 2023 17:43:31 +0000 (-0500) Subject: Refactor repeated code X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=d975be9593e56504aa5905b7b14766aa6a0d8a97;p=factbooks Refactor repeated code --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/article_listing.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/article_listing.kt index bfb7585..5bac26d 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/article_listing.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/article_listing.kt @@ -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.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()) diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/views_lore.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/views_lore.kt index 9a32057..e594946 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/views_lore.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/views_lore.kt @@ -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) {