1
0
forked from SPC/spc-site

Complete refactor to new routing API

This commit is contained in:
Alexander Nozik 2022-06-24 17:54:52 +03:00
parent 218e76a2a8
commit 072655ac51
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
3 changed files with 8 additions and 6 deletions

View File

@ -46,10 +46,13 @@ internal class KtorSiteBuilder(
private fun resolveRef(baseUrl: String, ref: String) = if (baseUrl.isEmpty()) {
ref
} else if (ref.isEmpty()) {
baseUrl
} else {
"${baseUrl.removeSuffix("/")}/$ref"
}
inner class KtorPageBuilder(
val pageBaseUrl: String,
override val meta: Meta = this@KtorSiteBuilder.meta,
@ -59,7 +62,7 @@ internal class KtorSiteBuilder(
override fun resolveRef(ref: String): String = resolveRef(pageBaseUrl, ref)
override fun resolvePageRef(pageName: Name): String = if(pageName.endsWith(SiteBuilder.INDEX_PAGE_TOKEN)){
override fun resolvePageRef(pageName: Name): String = if (pageName.endsWith(SiteBuilder.INDEX_PAGE_TOKEN)) {
resolveRef(pageName.cutLast().tokens.joinToString(separator = "/"))
} else {
resolveRef(pageName.tokens.joinToString(separator = "/"))

View File

@ -5,10 +5,7 @@ import space.kscience.dataforge.data.*
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.parseAsName
import space.kscience.dataforge.names.plus
import space.kscience.dataforge.names.startsWith
import space.kscience.dataforge.names.*
internal fun Name.toWebPath() = tokens.joinToString(separator = "/")
@ -25,7 +22,7 @@ interface PageBuilder : ContextAware {
fun PageBuilder.resolvePageRef(pageName: String) = resolvePageRef(pageName.parseAsName())
val PageBuilder.homeRef get() = resolvePageRef(Name.EMPTY).removeSuffix("/")
val PageBuilder.homeRef get() = resolvePageRef(SiteBuilder.INDEX_PAGE_TOKEN.asName())
/**
* Resolve a Html builder by its full name

View File

@ -58,6 +58,8 @@ internal class StaticSiteBuilder(
private fun resolveRef(baseUrl: String, ref: String) = if (baseUrl.isEmpty()) {
ref
} else if (ref.isEmpty()) {
baseUrl
} else {
"${baseUrl.removeSuffix("/")}/$ref"
}