1
0
forked from SPC/spc-site

Update language management

This commit is contained in:
Alexander Nozik 2024-02-23 12:11:06 +03:00
parent c2a60646f7
commit f1ee6c5942
3 changed files with 10 additions and 51 deletions

View File

@ -3,7 +3,6 @@ package center.sciprog
import io.ktor.server.application.Application import io.ktor.server.application.Application
import io.ktor.server.application.call import io.ktor.server.application.call
import io.ktor.server.application.install import io.ktor.server.application.install
import io.ktor.server.config.tryGetString
import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders
import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders
import io.ktor.server.response.respondRedirect import io.ktor.server.response.respondRedirect
@ -15,44 +14,6 @@ import space.kscience.dataforge.workspace.resources
import space.kscience.snark.html.SnarkHtml import space.kscience.snark.html.SnarkHtml
import space.kscience.snark.html.readSiteData import space.kscience.snark.html.readSiteData
import space.kscience.snark.ktor.site import space.kscience.snark.ktor.site
import java.nio.file.Path
//private fun Application.copyResource(resource: String, dataDirectory: Path) {
// val uri = javaClass.getResource("/$resource")?.toURI()
// ?: error("Resource $resource not found")
// val targetPath = dataDirectory.resolve(resource)
//
// if (Files.isDirectory(targetPath)) {
// log.info("Using existing data directory at $targetPath.")
// } else {
// log.info("Copying data from $uri into $targetPath.")
// targetPath.createDirectories()
// //Copy everything into a temporary directory
//
// fun copyFromPath(rootPath: Path) {
// Files.walk(rootPath).forEach { source: Path ->
// if (source.isRegularFile()) {
// val relative = source.relativeTo(rootPath).toString()
// val destination: Path = targetPath.resolve(relative)
// destination.parent.createDirectories()
// Files.copy(source, destination)
// }
// }
// }
//
// if ("jar" == uri.scheme) {
// FileSystems.newFileSystem(uri, emptyMap<String, Any>()).use { fs ->
// val rootPath: Path = fs.provider().getPath(uri)
// copyFromPath(rootPath)
// }
// } else {
// val rootPath = uri.toPath()
// copyFromPath(rootPath)
// }
// }
//}
@Suppress("unused") @Suppress("unused")
fun Application.spcModule() { fun Application.spcModule() {
@ -66,9 +27,9 @@ fun Application.spcModule() {
val snark = context.request(SnarkHtml) val snark = context.request(SnarkHtml)
val dataDirectory = Path.of( // val dataDirectory = Path.of(
environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data" // environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data"
) // )
val siteData = snark.readSiteData(context) { val siteData = snark.readSiteData(context) {
resources(snark.io, "common", "home", "magprog") resources(snark.io, "common", "home", "magprog")

View File

@ -17,8 +17,7 @@ import kotlin.collections.component2
import kotlin.collections.set import kotlin.collections.set
context(PageContextWithData) context(PageContextWithData, FlowContent) private fun spcSpotlightContent(
private fun FlowContent.spcSpotlightContent(
landing: Data<PageFragment>, landing: Data<PageFragment>,
content: Map<Name, Data<PageFragment>>, content: Map<Name, Data<PageFragment>>,
) { ) {

View File

@ -50,8 +50,7 @@ internal fun HTML.spcHead(title: String = SPC_TITLE) {
} }
} }
context(PageContext) context(PageContext, FlowContent) internal fun spcHomeMenu() {
internal fun FlowContent.spcHomeMenu() {
nav { nav {
id = "menu" id = "menu"
ul("links") { ul("links") {
@ -103,8 +102,8 @@ internal fun FlowContent.spcHomeMenu() {
} }
} }
context(PageContext) context(PageContext, FlowContent)
internal fun FlowContent.spcFooter() { internal fun spcFooter() {
footer { footer {
id = "footer" id = "footer"
div("inner") { div("inner") {
@ -155,8 +154,8 @@ internal fun FlowContent.spcFooter() {
} }
} }
context(PageContext) context(PageContextWithData, FlowContent)
internal fun FlowContent.wrapper(contentBody: FlowContent.() -> Unit) = postprocess{ internal fun wrapper(contentBody: FlowContent.() -> Unit) = postprocess {
div { div {
id = "wrapper" id = "wrapper"
// Header // Header
@ -169,7 +168,7 @@ internal fun FlowContent.wrapper(contentBody: FlowContent.() -> Unit) = postpro
} }
getLanguageMap().takeIf { it.isNotEmpty() }?.let { languageMap-> languageMap.takeIf { it.isNotEmpty() }?.let { languageMap ->
div { div {
languageMap.forEach { (key, meta) -> languageMap.forEach { (key, meta) ->
a(classes = "button primary small") { a(classes = "button primary small") {