From 1f0d0a812470effb1bf574b0ae0e47b7b80085bc Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 27 Mar 2023 10:23:25 +0300 Subject: [PATCH] Implemented binary propagation --- data/magprog/content/enroll.md | 2 +- gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 2 +- src/main/kotlin/center/sciprog/Application.kt | 49 ++++++------------- src/main/kotlin/center/sciprog/bmkLanding.kt | 21 ++++---- .../kotlin/center/sciprog/spcCollection.kt | 12 ++--- src/main/kotlin/center/sciprog/spcHome.kt | 19 +++---- src/main/kotlin/center/sciprog/spcMasters.kt | 24 +++++---- src/main/kotlin/center/sciprog/spcSite.kt | 21 ++++++++ .../kotlin/center/sciprog/staticRender.kt | 16 +++--- 11 files changed, 83 insertions(+), 87 deletions(-) create mode 100644 src/main/kotlin/center/sciprog/spcSite.kt diff --git a/data/magprog/content/enroll.md b/data/magprog/content/enroll.md index 8ad055e..c2b4d2d 100644 --- a/data/magprog/content/enroll.md +++ b/data/magprog/content/enroll.md @@ -5,7 +5,7 @@ section_title: Как поступить? language: ru --- Чтобы принять участие в программе, необходимо: -* заполнить **[анкету](https://docs.google.com/forms/d/e/1FAIpQLSf9w0zxHY90zI5Mze5XRKHLO7gxa__bro8PDC2PlwsPfcMkfw/viewform?usp=sf_link)**. В анкете надо указать одного или нескольких научных руководителей, с которыми вы бы хотели работать; +* заполнить **[анкету](https://forms.yandex.ru/cloud/641ad7fe73cee702c7753776/)**. В анкете надо указать одного или нескольких научных руководителей, с которыми вы бы хотели работать; * **до 30 июня** пройти собеседование с научными руководителями и согласовать предполагаемый план обучения; * подать документы в магистратуру МФТИ согласно [правилам поступления](https://pk.mipt.ru/master/) (направление **ЛФИ "Прикладная математика и физика"**, **ЛФИ "Ядерная физика и технологии"** или **ФПМИ "Информатика и вычислительная техника"**). Если есть соглашение с научным руководителем, но не удалось пройти по конкурсу, то обучение с большой вероятностью будет оплачено нашими партнерами. diff --git a/gradle.properties b/gradle.properties index 1859fbf..40a7e43 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official -toolsVersion=0.14.3-kotlin-1.8.10 +toolsVersion=0.14.5-kotlin-1.8.20-RC snarkVersion=0.1.0-dev-1 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb70..e1bef7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index cc3252a..2563170 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ rootProject.name = "spc-site" enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -enableFeaturePreview("VERSION_CATALOGS") +//enableFeaturePreview("VERSION_CATALOGS") pluginManagement { diff --git a/src/main/kotlin/center/sciprog/Application.kt b/src/main/kotlin/center/sciprog/Application.kt index 514c3de..9d66819 100644 --- a/src/main/kotlin/center/sciprog/Application.kt +++ b/src/main/kotlin/center/sciprog/Application.kt @@ -8,12 +8,20 @@ import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders import io.ktor.server.response.respondRedirect import io.ktor.server.routing.get import io.ktor.server.routing.routing -import space.kscience.snark.SnarkEnvironment -import space.kscience.snark.ktor.extractResources +import space.kscience.dataforge.context.Global +import space.kscience.dataforge.context.request +import space.kscience.dataforge.data.DataSet +import space.kscience.dataforge.data.DataTree +import space.kscience.dataforge.data.node +import space.kscience.dataforge.data.populateFrom +import space.kscience.dataforge.misc.DFExperimental +import space.kscience.snark.html.SiteBuilder +import space.kscience.snark.html.SnarkHtmlPlugin +import space.kscience.snark.html.readDirectory import space.kscience.snark.ktor.prepareSnarkDataCacheDirectory import space.kscience.snark.ktor.site import java.nio.file.Path -import kotlin.io.path.div + @Suppress("unused") fun Application.spcModule() { @@ -25,38 +33,13 @@ fun Application.spcModule() { prepareSnarkDataCacheDirectory(dataPath) - SnarkEnvironment.default.site { + val snark = Global.request(SnarkHtmlPlugin) + val siteData = snark.readDirectory(dataPath) - extractResources( - "/common", - dataPath / "common" - ) + site(snark, siteData, block = SiteBuilder::spcSite) - val homeDataPath = extractResources( - "/home", - dataPath / "home" - ) - - spcHome(dataPath = homeDataPath) - - val mastersDataPath = extractResources( - "/magprog", - dataPath / "magprog" - ) - - spcMasters(dataPath = mastersDataPath) - - val bmkDataPath = extractResources( - "/bmk", - dataPath / "bmk" - ) - - bmk(dataPath = bmkDataPath) - - } - - routing{ - get("magprog"){ + routing { + get("magprog") { call.respondRedirect("education/masters") } } diff --git a/src/main/kotlin/center/sciprog/bmkLanding.kt b/src/main/kotlin/center/sciprog/bmkLanding.kt index e9e1dfe..e57ca33 100644 --- a/src/main/kotlin/center/sciprog/bmkLanding.kt +++ b/src/main/kotlin/center/sciprog/bmkLanding.kt @@ -13,7 +13,6 @@ import space.kscience.dataforge.meta.string import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.parseAsName import space.kscience.snark.html.* -import java.nio.file.Path private val Data<*>.title: String @@ -23,21 +22,21 @@ private val Data<*>.fragment: String get() = meta["fragment"].string ?: "" -internal fun SiteBuilder.bmk(dataPath: Path, prefix: Name = "bmk".parseAsName()) { +internal fun SiteBuilder.bmk(data: DataTree, prefix: Name = "bmk".parseAsName()) { - val data: DataTree = snark.readDirectory(dataPath.resolve("content")) +// val data: DataTree = snark.readDirectory(dataPath.resolve("content")) site(prefix, data) { - file(dataPath.resolve("assets")) - file(dataPath.resolve("images")) - file(dataPath.resolve("../common/assets/webfonts"), "assets/webfonts") - file(dataPath.resolve("../common"), "") + static("assets") + static("images") + static("common.assets.webfonts", "assets/webfonts") + static("common", "") - val about: Data = data.resolveHtml("about")!! - val team: Data = data.resolveHtml("team.index")!! + val about: Data = data.resolveHtml("about") + val team: Data = data.resolveHtml("team.index") val teamData: Map> = data.resolveAllHtml { _, meta -> meta["type"].string == "team" } - val solutions: Data = data.resolveHtml("lotSeis")!! - val partners: Data = data.resolveHtml("partners")!! + val solutions: Data = data.resolveHtml("lotSeis") + val partners: Data = data.resolveHtml("partners") val partnersData = runBlocking { data.getByType("partnersData")!!.await() } page { diff --git a/src/main/kotlin/center/sciprog/spcCollection.kt b/src/main/kotlin/center/sciprog/spcCollection.kt index 3b1c67b..85f2e26 100644 --- a/src/main/kotlin/center/sciprog/spcCollection.kt +++ b/src/main/kotlin/center/sciprog/spcCollection.kt @@ -63,12 +63,8 @@ context(WebPage) private fun FlowContent.spcSpotlightContent( header("major") { h3 { +(entry.meta["title"].string ?: "???") } } - val infoData = data.resolveHtml(name.withIndex("info")) - if (infoData == null) { - htmlData(entry) - } else { - htmlData(infoData) - } + val infoData = data.resolveHtmlOrNull(name.replaceLast { NameToken(it.body + "[info]") }) ?: entry + htmlData(infoData) ul("actions") { li { a(classes = "button") { @@ -92,8 +88,8 @@ internal fun SiteBuilder.spcSpotlight( ) { val pageName = address.parseAsName() val languagePrefix = languagePrefix - val body = data.resolveHtml(languagePrefix + pageName) - ?: data.resolveHtml(pageName) ?: error("Could not find body for $pageName") + val body = data.resolveHtmlOrNull(languagePrefix + pageName) + ?: data.resolveHtmlOrNull(pageName) ?: error("Could not find body for $pageName") val content: Map> = data.resolveAllHtml { name, meta -> name.startsWith(languagePrefix) && contentFilter(name, meta) } diff --git a/src/main/kotlin/center/sciprog/spcHome.kt b/src/main/kotlin/center/sciprog/spcHome.kt index 0898531..98b5708 100644 --- a/src/main/kotlin/center/sciprog/spcHome.kt +++ b/src/main/kotlin/center/sciprog/spcHome.kt @@ -9,7 +9,6 @@ import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.startsWith import space.kscience.snark.html.* -import java.nio.file.Path import kotlin.reflect.typeOf @@ -68,7 +67,7 @@ internal val FortyDataRenderer: DataRenderer = object : DataRenderer { } page(name, dataMeta) { - spcPageContent{ + spcPageContent { htmlData(data) } } @@ -77,7 +76,7 @@ internal val FortyDataRenderer: DataRenderer = object : DataRenderer { } -context(WebPage) private fun HTML.spcHome() { +context(WebPage) private fun HTML.spcHomePage() { spcHead() body("is-preload") { wrapper { @@ -264,21 +263,20 @@ context(WebPage) private fun HTML.spcHome() { } } -internal fun SiteBuilder.spcHome(dataPath: Path, prefix: Name = Name.EMPTY) { +internal fun SiteBuilder.spcHome(homePageData: DataTree, prefix: Name = Name.EMPTY) { - val homePageData: DataTree = snark.readDirectory(dataPath.resolve("content")) + //val homePageData: DataTree = snark.readDirectory(dataPath.resolve("content")) site(prefix, homePageData) { - file(dataPath.resolve("assets")) - file(dataPath.resolve("images")) - file(dataPath.resolve("../common/assets/webfonts"), "assets/webfonts") - file(dataPath.resolve("../common"), "") + static("assets") + static("images") + static("common", "") withLanguages( "en" to "", "ru" to "ru" ) { - page { spcHome() } + page { spcHomePage() } localizedPages("consulting", dataRenderer = FortyDataRenderer) @@ -293,5 +291,4 @@ internal fun SiteBuilder.spcHome(dataPath: Path, prefix: Name = Name.EMPTY) { } } } - } diff --git a/src/main/kotlin/center/sciprog/spcMasters.kt b/src/main/kotlin/center/sciprog/spcMasters.kt index f94a92e..3efb4ad 100644 --- a/src/main/kotlin/center/sciprog/spcMasters.kt +++ b/src/main/kotlin/center/sciprog/spcMasters.kt @@ -12,7 +12,6 @@ import space.kscience.dataforge.meta.string import space.kscience.dataforge.names.* import space.kscience.snark.SnarkContext import space.kscience.snark.html.* -import java.nio.file.Path import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.collections.set @@ -70,8 +69,8 @@ private val RECOMMENDED_COURSES_PATH: Name = CONTENT_NODE_NAME + "recommendedCou private val PARTNERS_PATH: Name = CONTENT_NODE_NAME + "partners" context(WebPage) private fun FlowContent.programSection() { - val programBlock = data.resolveHtml(PROGRAM_PATH)!! - val recommendedBlock = data.resolveHtml(RECOMMENDED_COURSES_PATH)!! + val programBlock = data.resolveHtmlOrNull(PROGRAM_PATH)!! + val recommendedBlock = data.resolveHtmlOrNull(RECOMMENDED_COURSES_PATH)!! div("inner") { h2 { +"Учебная программа" } htmlData(programBlock) @@ -199,7 +198,7 @@ context(WebPage) private fun FlowContent.mentors() { h2 { a(href = ref) { +mentor.name } } - val info = data.resolveHtml(name.withIndex("info")) + val info = data.resolveHtmlOrNull(name.replaceLast { NameToken(it.body + "[info]") }) if (info != null) { htmlData(info) } @@ -300,19 +299,18 @@ context(WebPage) internal fun BODY.magProgFooter() { context(SnarkContext) private val HtmlData.mentorPageId get() = "mentor-${id}" -internal fun SiteBuilder.spcMasters(dataPath: Path, prefix: Name = "education.masters".parseAsName()) { +internal fun SiteBuilder.spcMasters(magProgData: DataTree, prefix: Name = "education.masters".parseAsName()) { - val magProgData: DataTree = snark.readDirectory(dataPath.resolve("content")) + //val magProgData: DataTree = snark.readDirectory(dataPath.resolve("content")) site(prefix, magProgData) { - file(dataPath.resolve("assets")) - file(dataPath.resolve("images")) - file(dataPath.resolve("../common/assets/webfonts"), "assets/webfonts") - file(dataPath.resolve("../common"), "") + static("assets") + static("images") + static("common", "") page { val sections = listOf( - wrapSection(data.resolveHtml(INTRO_PATH)!!, "intro"), + wrapSection(page.data.resolveHtmlOrNull(INTRO_PATH)!!, "intro"), MagProgSection( id = "partners", title = "Партнеры", @@ -335,9 +333,9 @@ internal fun SiteBuilder.spcMasters(dataPath: Path, prefix: Name = "education.ma ) { programSection() }, - wrapSection(data.resolveHtml(ENROLL_PATH)!!, "enroll"), + wrapSection(page.data.resolveHtmlOrNull(ENROLL_PATH)!!, "enroll"), wrapSection(id = "contacts", title = "Контакты") { - htmlData(data.resolveHtml(CONTACTS_PATH)!!) + htmlData(page.data.resolveHtmlOrNull(CONTACTS_PATH)!!) team() } ) diff --git a/src/main/kotlin/center/sciprog/spcSite.kt b/src/main/kotlin/center/sciprog/spcSite.kt new file mode 100644 index 0000000..18e0632 --- /dev/null +++ b/src/main/kotlin/center/sciprog/spcSite.kt @@ -0,0 +1,21 @@ +package center.sciprog + +import space.kscience.dataforge.data.* +import space.kscience.dataforge.misc.DFExperimental +import space.kscience.dataforge.names.Name +import space.kscience.snark.html.SiteBuilder + +@OptIn(DFExperimental::class) +private fun DataSet.siteData(branchName: String): DataTree = DataTree(dataType) { + populateFrom(branch(Name.of(branchName, "content"))) + node("common", branch("common")) + node("assets", branch(Name.of(branchName, "assets"))) + node("images", branch(Name.of(branchName, "images"))) +} + +fun SiteBuilder.spcSite() { +// val commonData = data.branch("common") + spcHome(data.siteData("home")) + spcMasters(data.siteData("magprog")) +// bmk(data.branch("bmk").withBranch("common", commonData)) +} \ No newline at end of file diff --git a/src/main/kotlin/center/sciprog/staticRender.kt b/src/main/kotlin/center/sciprog/staticRender.kt index c10e8d0..c914631 100644 --- a/src/main/kotlin/center/sciprog/staticRender.kt +++ b/src/main/kotlin/center/sciprog/staticRender.kt @@ -1,14 +1,16 @@ package center.sciprog -import space.kscience.snark.SnarkEnvironment +import space.kscience.dataforge.context.Global +import space.kscience.dataforge.context.request +import space.kscience.snark.html.SiteBuilder +import space.kscience.snark.html.SnarkHtmlPlugin +import space.kscience.snark.html.readResourceDirectory import space.kscience.snark.html.static import java.nio.file.Path -import kotlin.io.path.toPath fun main() { - SnarkEnvironment.default.static(Path.of("build/public"), siteUrl = "") { - spcHome(dataPath = javaClass.getResource("/home")!!.toURI().toPath()) - spcMasters(dataPath = javaClass.getResource("/magprog")!!.toURI().toPath()) - bmk(dataPath = javaClass.getResource("/bmk")!!.toURI().toPath()) - } + val snark = Global.request(SnarkHtmlPlugin) + val siteData = snark.readResourceDirectory() + + snark.static(siteData, Path.of("build/public"), siteUrl = "", block = SiteBuilder::spcSite) } \ No newline at end of file