From 285057fbb061416f570a64c21b00c60dcd0e3103 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 20 Jun 2022 20:32:44 +0300 Subject: [PATCH] bug in PagesFrom --- src/main/kotlin/space/kscience/snark/pages.kt | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/space/kscience/snark/pages.kt b/src/main/kotlin/space/kscience/snark/pages.kt index d7d3601..529ac90 100644 --- a/src/main/kotlin/space/kscience/snark/pages.kt +++ b/src/main/kotlin/space/kscience/snark/pages.kt @@ -2,10 +2,7 @@ package space.kscience.snark import io.ktor.server.application.call import io.ktor.server.html.respondHtml -import io.ktor.server.http.content.* -import io.ktor.server.routing.Route import io.ktor.server.routing.get -import io.ktor.server.routing.route import space.kscience.dataforge.data.DataTree import space.kscience.dataforge.data.DataTreeItem import space.kscience.dataforge.data.await @@ -17,44 +14,45 @@ import space.kscience.dataforge.meta.string import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.plus +import java.nio.file.Path import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.reflect.typeOf internal const val DESIGNATION_KEY = "designation" -private fun Route.staticFrom(rootMeta: Meta) = static { - rootMeta.getIndexed("resource".asName()).forEach { (_, meta) -> - val resourcePackage by meta.string() - val remotePath by meta.string() - val resourceName by meta.string() - - //If remote path provided, use a single resource - remotePath?.let { - resource(it, resourceName ?: it, resourcePackage) - return@forEach - } - - //otherwise use package resources - resources(resourcePackage) - } +private fun SnarkRoute.staticFrom(rootMeta: Meta) { +// rootMeta.getIndexed("resource".asName()).forEach { (_, meta) -> +// val resourcePackage by meta.string() +// val remotePath by meta.string() +// val resourceName by meta.string() +// +// //If remote path provided, use a single resource +// remotePath?.let { +// resource(it, resourceName ?: it, resourcePackage) +// return@forEach +// } +// +// //otherwise use package resources +// resources(resourcePackage) +// } rootMeta.getIndexed("file".asName()).forEach { (_, meta) -> val remotePath by meta.string { error("File remote path is not provided") } val path by meta.string { error("File path is not provided") } - file(remotePath, path) + staticFile(remotePath, Path.of(path)) } rootMeta.getIndexed("directory".asName()).forEach { (_, meta) -> val path by meta.string { error("Directory path is not provided") } - files(path) + staticDirectory("", Path.of(path)) } } /** * Represent pages in a [DataTree] */ -fun Route.pagesFrom(prefix: Name, data: DataTree<*>) { +context(PageContext) fun SnarkRoute.pagesFrom(prefix: Name, data: DataTree<*>) { if (data.meta[DESIGNATION_KEY].string == "page") { TODO("Implement node-based pages") // route(prefix.tokens.joinToString(separator = "/")) {