forked from SPC/spc-site
Update to DataForge 0.8
This commit is contained in:
parent
72ac07db5a
commit
671ae6357f
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,7 +1,7 @@
|
|||||||
.gradle/
|
.gradle/
|
||||||
build/
|
build/
|
||||||
.idea/
|
.idea/
|
||||||
/logs/
|
logs/
|
||||||
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
/deploy.ps1
|
/deploy.ps1
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
|
|
||||||
toolsVersion=0.15.2-kotlin-1.9.21
|
toolsVersion=0.15.2-kotlin-1.9.22
|
||||||
snarkVersion=0.1.0-dev-1
|
snarkVersion=0.1.0-dev-1
|
@ -11,14 +11,8 @@ import io.ktor.server.routing.get
|
|||||||
import io.ktor.server.routing.routing
|
import io.ktor.server.routing.routing
|
||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.dataforge.context.request
|
import space.kscience.dataforge.context.request
|
||||||
import space.kscience.dataforge.data.DataSourceBuilder
|
import space.kscience.dataforge.workspace.resources
|
||||||
import space.kscience.dataforge.io.IOPlugin
|
|
||||||
import space.kscience.dataforge.misc.DFExperimental
|
|
||||||
import space.kscience.dataforge.names.Name
|
|
||||||
import space.kscience.dataforge.workspace.monitorRawDirectory
|
|
||||||
import space.kscience.dataforge.workspace.readResources
|
|
||||||
import space.kscience.snark.html.SnarkHtml
|
import space.kscience.snark.html.SnarkHtml
|
||||||
import space.kscience.snark.html.fill
|
|
||||||
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
|
import java.nio.file.Path
|
||||||
@ -59,21 +53,6 @@ import java.nio.file.Path
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
context(IOPlugin)
|
|
||||||
@OptIn(DFExperimental::class)
|
|
||||||
fun DataSourceBuilder<Any>.directory(path: Path, name: Name = Name.EMPTY) {
|
|
||||||
node(name, monitorRawDirectory(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
context(IOPlugin)
|
|
||||||
@OptIn(DFExperimental::class)
|
|
||||||
fun DataSourceBuilder<Any>.resource(
|
|
||||||
resource: String,
|
|
||||||
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
|
|
||||||
) {
|
|
||||||
fill(readResources(resource, classLoader = classLoader))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun Application.spcModule() {
|
fun Application.spcModule() {
|
||||||
@ -92,10 +71,7 @@ fun Application.spcModule() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val siteData = snark.readSiteData(context) {
|
val siteData = snark.readSiteData(context) {
|
||||||
resource("common")
|
resources(snark.io, "common", "home", "magprog")
|
||||||
resource("home")
|
|
||||||
resource("magprog")
|
|
||||||
//directory(dataDirectory)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
routing {
|
routing {
|
||||||
|
@ -7,7 +7,10 @@ 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.*
|
import space.kscience.dataforge.names.Name
|
||||||
|
import space.kscience.dataforge.names.NameToken
|
||||||
|
import space.kscience.dataforge.names.parseAsName
|
||||||
|
import space.kscience.dataforge.names.replaceLast
|
||||||
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
|
||||||
@ -90,11 +93,8 @@ internal fun SiteContextWithData.spcSpotlight(
|
|||||||
contentFilter: (Name, Meta) -> Boolean,
|
contentFilter: (Name, Meta) -> Boolean,
|
||||||
) {
|
) {
|
||||||
val pageName = address.parseAsName()
|
val pageName = address.parseAsName()
|
||||||
val languagePrefix = languagePrefix
|
val body = siteData.resolveHtmlOrNull(pageName) ?: error("Could not find body for $pageName")
|
||||||
val body = siteData.resolveHtmlOrNull(languagePrefix + pageName)
|
val content: Map<Name, Data<PageFragment>> = siteData.resolveAllHtml { name, meta -> contentFilter(name, meta) }
|
||||||
?: siteData.resolveHtmlOrNull(pageName) ?: error("Could not find body for $pageName")
|
|
||||||
val content: Map<Name, Data<PageFragment>> =
|
|
||||||
siteData.resolveAllHtml { name, meta -> name.startsWith(languagePrefix) && contentFilter(name, meta) }
|
|
||||||
|
|
||||||
val meta = body.meta
|
val meta = body.meta
|
||||||
page(pageName) {
|
page(pageName) {
|
||||||
|
@ -234,7 +234,7 @@ internal val spcHomePage = HtmlPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun SiteContextWithData.allPagesIn(location: String){
|
private fun SiteContextWithData.allPagesIn(location: String){
|
||||||
siteData.filterByType<PageFragment> { name, meta ->
|
siteData.filterByType<PageFragment> { name, meta, _ ->
|
||||||
name.startsWith(location) && meta["type"].string == "page"
|
name.startsWith(location) && meta["type"].string == "page"
|
||||||
}.forEach { (name, content) ->
|
}.forEach { (name, content) ->
|
||||||
page(name, content = spcPage(content))
|
page(name, content = spcPage(content))
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package center.sciprog
|
package center.sciprog
|
||||||
|
|
||||||
import space.kscience.dataforge.data.*
|
import space.kscience.dataforge.data.DataTree
|
||||||
import space.kscience.dataforge.misc.DFExperimental
|
import space.kscience.dataforge.data.branch
|
||||||
|
import space.kscience.dataforge.data.putAll
|
||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.snark.html.HtmlSite
|
import space.kscience.snark.html.HtmlSite
|
||||||
import space.kscience.snark.html.site
|
import space.kscience.snark.html.site
|
||||||
|
|
||||||
@OptIn(DFExperimental::class)
|
private inline fun <reified T> DataTree<T>.contentFor(branchName: String): DataTree<T> = DataTree{
|
||||||
private fun <T : Any> DataSet<T>.contentFor(branchName: String): DataTree<T> = DataTree(dataType) {
|
putAll(branch(Name.of(branchName, "content")) ?: DataTree.EMPTY)
|
||||||
populateFrom(branch(Name.of(branchName, "content")))
|
branch("common", branch("common") ?: DataTree.EMPTY)
|
||||||
node("common", branch("common"))
|
branch("assets", branch(Name.of(branchName, "assets")) ?: DataTree.EMPTY)
|
||||||
node("assets", branch(Name.of(branchName, "assets")))
|
branch("images", branch(Name.of(branchName, "images")) ?: DataTree.EMPTY)
|
||||||
node("images", branch(Name.of(branchName, "images")))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val spcSite = HtmlSite {
|
val spcSite = HtmlSite {
|
||||||
|
@ -3,6 +3,7 @@ package center.sciprog
|
|||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.dataforge.context.request
|
import space.kscience.dataforge.context.request
|
||||||
|
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.html.static.staticSite
|
import space.kscience.snark.html.static.staticSite
|
||||||
@ -17,10 +18,7 @@ suspend fun main(args: Array<String>) = coroutineScope {
|
|||||||
|
|
||||||
val snark = context.request(SnarkHtml)
|
val snark = context.request(SnarkHtml)
|
||||||
val siteData = snark.readSiteData(context) {
|
val siteData = snark.readSiteData(context) {
|
||||||
resource("common")
|
resources(snark.io,"common", "home", "magprog")
|
||||||
resource("home")
|
|
||||||
resource("magprog")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
snark.staticSite(siteData, Path.of(destinationPath), content = spcSite)
|
snark.staticSite(siteData, Path.of(destinationPath), content = spcSite)
|
||||||
|
Loading…
Reference in New Issue
Block a user