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