1
0
forked from SPC/spc-site

bug in PagesFrom

This commit is contained in:
Alexander Nozik 2022-06-20 20:32:44 +03:00
parent 23a736a012
commit 285057fbb0
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357

View File

@ -2,10 +2,7 @@ package space.kscience.snark
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.html.respondHtml 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.get
import io.ktor.server.routing.route
import space.kscience.dataforge.data.DataTree import space.kscience.dataforge.data.DataTree
import space.kscience.dataforge.data.DataTreeItem import space.kscience.dataforge.data.DataTreeItem
import space.kscience.dataforge.data.await 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.Name
import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus import space.kscience.dataforge.names.plus
import java.nio.file.Path
import kotlin.collections.component1 import kotlin.collections.component1
import kotlin.collections.component2 import kotlin.collections.component2
import kotlin.reflect.typeOf import kotlin.reflect.typeOf
internal const val DESIGNATION_KEY = "designation" internal const val DESIGNATION_KEY = "designation"
private fun Route.staticFrom(rootMeta: Meta) = static { private fun SnarkRoute.staticFrom(rootMeta: Meta) {
rootMeta.getIndexed("resource".asName()).forEach { (_, meta) -> // rootMeta.getIndexed("resource".asName()).forEach { (_, meta) ->
val resourcePackage by meta.string() // val resourcePackage by meta.string()
val remotePath by meta.string() // val remotePath by meta.string()
val resourceName by meta.string() // val resourceName by meta.string()
//
//If remote path provided, use a single resource // //If remote path provided, use a single resource
remotePath?.let { // remotePath?.let {
resource(it, resourceName ?: it, resourcePackage) // resource(it, resourceName ?: it, resourcePackage)
return@forEach // return@forEach
} // }
//
//otherwise use package resources // //otherwise use package resources
resources(resourcePackage) // resources(resourcePackage)
} // }
rootMeta.getIndexed("file".asName()).forEach { (_, meta) -> rootMeta.getIndexed("file".asName()).forEach { (_, meta) ->
val remotePath by meta.string { error("File remote path is not provided") } val remotePath by meta.string { error("File remote path is not provided") }
val path by meta.string { error("File 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) -> rootMeta.getIndexed("directory".asName()).forEach { (_, meta) ->
val path by meta.string { error("Directory path is not provided") } val path by meta.string { error("Directory path is not provided") }
files(path) staticDirectory("", Path.of(path))
} }
} }
/** /**
* Represent pages in a [DataTree] * 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") { if (data.meta[DESIGNATION_KEY].string == "page") {
TODO("Implement node-based pages") TODO("Implement node-based pages")
// route(prefix.tokens.joinToString(separator = "/")) { // route(prefix.tokens.joinToString(separator = "/")) {