Path universalization + bugfixes
This commit is contained in:
parent
431a710459
commit
44a2cf4cf3
@ -13,10 +13,10 @@ import ru.mipt.spc.magprog.magProgPage
|
||||
import space.kscience.dataforge.context.Context
|
||||
import space.kscience.snark.SnarkPlugin
|
||||
import java.net.URI
|
||||
import java.nio.file.FileSystemNotFoundException
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.*
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.relativeTo
|
||||
|
||||
fun CommonAttributeGroupFacade.css(block: CssBuilder.() -> Unit) {
|
||||
style = CssBuilder().block().toString()
|
||||
@ -29,28 +29,39 @@ private fun useResource(uri: URI, block: (Path) -> Unit) {
|
||||
try {
|
||||
block(Paths.get(uri))
|
||||
} catch (ex: FileSystemNotFoundException) {
|
||||
//Copy everything into a temporary directory
|
||||
FileSystems.newFileSystem(uri, emptyMap<String, Any>()).use { fs ->
|
||||
val p: Path = fs.provider().getPath(uri)
|
||||
block(p)
|
||||
val rootPath: Path = fs.provider().getPath(uri)
|
||||
val tmpDirectory = Files.createTempDirectory("snark")
|
||||
Files.walk(rootPath).forEach { source: Path ->
|
||||
if (source.isRegularFile()) {
|
||||
val relative = source.relativeTo(rootPath).toString()
|
||||
val destination: Path = tmpDirectory.resolve(relative)
|
||||
destination.parent.createDirectories()
|
||||
Files.copy(source, destination)
|
||||
}
|
||||
}
|
||||
block(tmpDirectory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun main() {
|
||||
val context = Context("spc-site") {
|
||||
plugin(SnarkPlugin)
|
||||
}
|
||||
embeddedServer(Netty, port = 8080, watchPaths = listOf("classes", "resources")) {
|
||||
useResource(javaClass.getResource("/magprog")!!.toURI()) {
|
||||
install(StatusPages) {
|
||||
exception<AuthenticationException> { call, _ ->
|
||||
call.respond(HttpStatusCode.Unauthorized)
|
||||
}
|
||||
exception<AuthorizationException> { call, _ ->
|
||||
call.respond(HttpStatusCode.Forbidden)
|
||||
}
|
||||
embeddedServer(Netty, port = 7080, watchPaths = listOf("classes", "resources")) {
|
||||
install(StatusPages) {
|
||||
exception<AuthenticationException> { call, _ ->
|
||||
call.respond(HttpStatusCode.Unauthorized)
|
||||
}
|
||||
magProgPage(context, rootPath = it)
|
||||
exception<AuthorizationException> { call, _ ->
|
||||
call.respond(HttpStatusCode.Forbidden)
|
||||
}
|
||||
}
|
||||
useResource(javaClass.getResource("/magprog")!!.toURI()) { path ->
|
||||
magProgPage(context, rootPath = path)
|
||||
}
|
||||
}.start(wait = true)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package ru.mipt.spc.magprog
|
||||
|
||||
import io.ktor.server.application.Application
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.html.div
|
||||
import kotlinx.html.unsafe
|
||||
@ -25,6 +26,7 @@ import kotlin.reflect.full.isSubtypeOf
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
class DataSetPageContext(
|
||||
val application: Application,
|
||||
override val context: Context,
|
||||
val prefix: String,
|
||||
val dataSet: DataSet<Any>,
|
||||
|
@ -25,12 +25,8 @@ import space.kscience.snark.*
|
||||
import java.nio.file.Path
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlin.collections.forEach
|
||||
import kotlin.collections.listOf
|
||||
import kotlin.collections.map
|
||||
import kotlin.collections.mapValues
|
||||
import kotlin.collections.set
|
||||
import kotlin.collections.sortedBy
|
||||
|
||||
|
||||
//fun CssBuilder.magProgCss() {
|
||||
// rule(".magprog-body") {
|
||||
@ -144,12 +140,14 @@ context(PageContext) private fun FlowContent.team() {
|
||||
team.forEach { member ->
|
||||
section {
|
||||
id = member.id
|
||||
div("image left") {
|
||||
a(classes = "image", href = resolveRef("mentor-${member.id}")) {
|
||||
member.photo?.let { photoPath ->
|
||||
img(
|
||||
src = resolveRef(photoPath),
|
||||
alt = member.name
|
||||
)
|
||||
) {
|
||||
attributes["data-position"] = "center center"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,13 +174,13 @@ context(PageContext) private fun FlowContent.mentors() {
|
||||
mentors.forEach { (name, mentor) ->
|
||||
section {
|
||||
id = mentor.id
|
||||
div("image left") {
|
||||
a(classes = "image", href = resolveRef("mentor-${mentor.id}")) {
|
||||
mentor.photo?.let { photoPath ->
|
||||
a(href = resolveRef("mentor-${mentor.id}")) {
|
||||
img(
|
||||
src = resolveRef(photoPath),
|
||||
alt = mentor.name
|
||||
)
|
||||
img(
|
||||
src = resolveRef(photoPath),
|
||||
alt = mentor.name
|
||||
) {
|
||||
attributes["data-position"] = "center center"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -260,9 +258,6 @@ context(PageContext) internal fun BODY.magProgFooter() {
|
||||
script {
|
||||
src = resolveRef("js/util.js")
|
||||
}
|
||||
script {
|
||||
src = resolveRef("js/bootstrap.min.js")
|
||||
}
|
||||
script {
|
||||
src = resolveRef("js/main.js")
|
||||
}
|
||||
@ -270,13 +265,12 @@ context(PageContext) internal fun BODY.magProgFooter() {
|
||||
|
||||
internal val Person.mentorPageId get() = "mentor-${id}"
|
||||
|
||||
|
||||
internal fun Application.magProgPage(context: Context, rootPath: Path, prefix: String = "/magprog") {
|
||||
val io = context.io
|
||||
val content = DirectoryDataTree(io, rootPath.resolve("content"))
|
||||
|
||||
|
||||
val magprogPageContext: PageContext = DataSetPageContext(context, prefix, content)
|
||||
val magprogPageContext: PageContext = DataSetPageContext(this, context, prefix, content)
|
||||
|
||||
routing {
|
||||
route(prefix) {
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user