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.call
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.XForwardedHeaders
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.readSiteData
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")
fun Application.spcModule() {
@ -66,9 +27,9 @@ fun Application.spcModule() {
val snark = context.request(SnarkHtml)
val dataDirectory = Path.of(
environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data"
)
// val dataDirectory = Path.of(
// environment.config.tryGetString("ktor.environment.dataDirectory") ?: "data"
// )
val siteData = snark.readSiteData(context) {
resources(snark.io, "common", "home", "magprog")

View File

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

View File

@ -50,8 +50,7 @@ internal fun HTML.spcHead(title: String = SPC_TITLE) {
}
}
context(PageContext)
internal fun FlowContent.spcHomeMenu() {
context(PageContext, FlowContent) internal fun spcHomeMenu() {
nav {
id = "menu"
ul("links") {
@ -103,8 +102,8 @@ internal fun FlowContent.spcHomeMenu() {
}
}
context(PageContext)
internal fun FlowContent.spcFooter() {
context(PageContext, FlowContent)
internal fun spcFooter() {
footer {
id = "footer"
div("inner") {
@ -155,8 +154,8 @@ internal fun FlowContent.spcFooter() {
}
}
context(PageContext)
internal fun FlowContent.wrapper(contentBody: FlowContent.() -> Unit) = postprocess{
context(PageContextWithData, FlowContent)
internal fun wrapper(contentBody: FlowContent.() -> Unit) = postprocess {
div {
id = "wrapper"
// 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 {
languageMap.forEach { (key, meta) ->
a(classes = "button primary small") {