diff --git a/src/main/kotlin/ru/mipt/spc/spcCollection.kt b/src/main/kotlin/ru/mipt/spc/spcCollection.kt index 2ccb3a7..cb22291 100644 --- a/src/main/kotlin/ru/mipt/spc/spcCollection.kt +++ b/src/main/kotlin/ru/mipt/spc/spcCollection.kt @@ -2,13 +2,12 @@ package ru.mipt.spc import html5up.forty.fortyScripts import kotlinx.html.* +import space.kscience.dataforge.data.Data import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.int import space.kscience.dataforge.meta.string -import space.kscience.dataforge.names.Name -import space.kscience.dataforge.names.parseAsName -import space.kscience.dataforge.names.withIndex +import space.kscience.dataforge.names.* import space.kscience.snark.html.* import kotlin.collections.component1 import kotlin.collections.component2 @@ -91,15 +90,17 @@ internal fun SiteBuilder.spcSpotlight( address: String, contentFilter: (Name, Meta) -> Boolean, ) { - val name = address.parseAsName() - val body = data.resolveHtml(name) ?: error("Could not find body for $name") - val content = data.resolveAllHtml(contentFilter) + val pageName = address.parseAsName() + val languagePrefix = languagePrefix + val body = data.resolveHtml(languagePrefix + pageName) + ?: data.resolveHtml(pageName) ?: error("Could not find body for $pageName") + val content: Map> = + data.resolveAllHtml { name, meta -> name.startsWith(languagePrefix) && contentFilter(name, meta) } val meta = body.meta - page(name) { + page(pageName) { val title by meta.string { SPC_TITLE } - val pageName by meta.string { title } - spcHead(pageName) + spcHead(title) body("is-preload") { wrapper { spcSpotlightContent(body, content) @@ -110,8 +111,8 @@ internal fun SiteBuilder.spcSpotlight( } content.forEach { (name, contentBody) -> - page(name) { - spcPageContent(contentBody.meta) { + page(name, contentBody.meta) { + spcPageContent { htmlData(contentBody) } } diff --git a/src/main/kotlin/ru/mipt/spc/spcHome.kt b/src/main/kotlin/ru/mipt/spc/spcHome.kt index 28652a7..2cc77c4 100644 --- a/src/main/kotlin/ru/mipt/spc/spcHome.kt +++ b/src/main/kotlin/ru/mipt/spc/spcHome.kt @@ -13,11 +13,10 @@ import kotlin.reflect.typeOf context(WebPage) internal fun HTML.spcPageContent( - meta: Meta, fragment: FlowContent.() -> Unit, ) { - val title by meta.string { SPC_TITLE } - val pageName by meta.string { title } + val title by pageMeta.string { SPC_TITLE } + val pageName by pageMeta.string { title } spcHead(pageName) body("is-preload") { wrapper { @@ -29,7 +28,7 @@ context(WebPage) internal fun HTML.spcPageContent( header("major") { h1 { +title } } - meta["image"]?.let { imageMeta -> + pageMeta["image"]?.let { imageMeta -> val imagePath = imageMeta.value?.string ?: imageMeta["path"].string ?: error("Image path not provided") val imageClass = imageMeta["position"].string ?: "main" @@ -63,12 +62,12 @@ internal val FortyDataRenderer: DataRenderer = object : DataRenderer { data.meta } else { data.meta.toMutableMeta().apply { - "language" put languageMeta + "languages" put languageMeta } } - page(name, data.meta) { - spcPageContent(dataMeta) { + page(name, dataMeta) { + spcPageContent{ htmlData(data) } } @@ -279,9 +278,9 @@ internal fun SiteBuilder.spcHome(dataPath: Path, prefix: Name = Name.EMPTY) { ) { page { spcHome() } - pages("consulting", dataRenderer = FortyDataRenderer) + localizedPages("consulting", dataRenderer = FortyDataRenderer) - pages("education", dataRenderer = FortyDataRenderer) + localizedPages("education", dataRenderer = FortyDataRenderer) spcSpotlight("team") { _, meta -> meta["type"].string == "team" diff --git a/src/main/kotlin/ru/mipt/spc/spcMisc.kt b/src/main/kotlin/ru/mipt/spc/spcMisc.kt index c5f5664..81e0f5b 100644 --- a/src/main/kotlin/ru/mipt/spc/spcMisc.kt +++ b/src/main/kotlin/ru/mipt/spc/spcMisc.kt @@ -1,15 +1,19 @@ package ru.mipt.spc import kotlinx.html.* +import space.kscience.dataforge.meta.get +import space.kscience.dataforge.meta.string import space.kscience.snark.html.WebPage import space.kscience.snark.html.homeRef +import space.kscience.snark.html.languages import space.kscience.snark.html.resolvePageRef import java.time.LocalDate internal const val SPC_TITLE = "Scientific Programming Centre" -context(WebPage) internal fun HTML.spcHead(title: String = SPC_TITLE) { +context(WebPage) +internal fun HTML.spcHead(title: String = SPC_TITLE) { head { title { +title @@ -49,7 +53,8 @@ context(WebPage) internal fun HTML.spcHead(title: String = SPC_TITLE) { } } -context(WebPage) internal fun FlowContent.spcHomeMenu() { +context(WebPage) +internal fun FlowContent.spcHomeMenu() { nav { id = "menu" ul("links") { @@ -101,7 +106,8 @@ context(WebPage) internal fun FlowContent.spcHomeMenu() { } } -context(WebPage) internal fun FlowContent.spcFooter() { +context(WebPage) +internal fun FlowContent.spcFooter() { footer { id = "footer" div("inner") { @@ -139,7 +145,7 @@ context(WebPage) internal fun FlowContent.spcFooter() { } ul("copyright") { li { +"""SPC. All rights reserved.""" } - li { +"Updated on ${LocalDate.now()}"} + li { +"Updated on ${LocalDate.now()}" } li { +"""Design:""" a { @@ -152,7 +158,8 @@ context(WebPage) internal fun FlowContent.spcFooter() { } } -context(WebPage) internal fun FlowContent.wrapper(contentBody: FlowContent.() -> Unit) { +context(WebPage) +internal fun FlowContent.wrapper(contentBody: FlowContent.() -> Unit) { div { id = "wrapper" // Header @@ -163,6 +170,19 @@ context(WebPage) internal fun FlowContent.wrapper(contentBody: FlowContent.() -> strong { +"""SPC""" } span { +"""Scientific Programming Centre""" } } + + + if (languages.isNotEmpty()) { + div { + languages.forEach { (key, meta) -> + a(classes = "button primary small") { + href = resolvePageRef(meta["target"].string ?: "#") + +key + } + } + } + } + nav { a { href = "#menu"