1
0
forked from SPC/spc-site

Fixing static gen after refactor

This commit is contained in:
Alexander Nozik 2022-06-24 18:46:15 +03:00
parent 072655ac51
commit f530b7605b
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
6 changed files with 17 additions and 7 deletions

View File

@ -327,7 +327,10 @@ internal fun SiteBuilder.spcMaster(dataPath: Path, prefix: Name = "magprog".asNa
nav {
ul {
li {
a(classes = "spc-home", href = "/") {
a(
classes = "spc-home",
href = resolvePageRef(Name.of("..") + SiteBuilder.INDEX_PAGE_TOKEN)
) {
i("fa fa-home") {
attributes["aria-hidden"] = "true"
}

View File

@ -186,7 +186,7 @@ context(PageBuilder) private fun HTML.spcHome() {
header("major") {
h3 {
a(classes = "link") {
href = resolvePageRef("consulting")
href = resolvePageRef("consulting.index")
+"""Consulting"""
}
}

View File

@ -63,9 +63,9 @@ 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)) {
resolveRef(pageName.cutLast().tokens.joinToString(separator = "/"))
resolveRef(pageName.cutLast().toWebPath())
} else {
resolveRef(pageName.tokens.joinToString(separator = "/"))
resolveRef(pageName.toWebPath())
}
}

View File

@ -7,7 +7,13 @@ import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.string
import space.kscience.dataforge.names.*
internal fun Name.toWebPath() = tokens.joinToString(separator = "/")
internal fun Name.toWebPath() = tokens.joinToString(separator = "/"){
if (it.hasIndex()) {
"${it.body}[${it.index}]"
} else {
it.body
}
}
interface PageBuilder : ContextAware {
val data: DataTree<*>

View File

@ -50,6 +50,7 @@ interface SiteBuilder : ContextAware {
companion object {
val INDEX_PAGE_TOKEN: NameToken = NameToken("index")
val UP_PAGE_TOKEN: NameToken = NameToken("..")
}
}

View File

@ -73,7 +73,7 @@ internal class StaticSiteBuilder(
override fun resolveRef(ref: String): String = resolveRef(baseUrl, ref)
override fun resolvePageRef(pageName: Name): String = resolveRef(
pageName.tokens.joinToString(separator = "/", postfix = ".html")
pageName.toWebPath() + ".html"
)
}
@ -116,7 +116,7 @@ internal class StaticSiteBuilder(
fun SnarkPlugin.static(
outputPath: Path,
data: DataTree<*> = DataTree.empty(),
siteUrl: String = outputPath.absolutePathString(),
siteUrl: String = outputPath.absolutePathString().replace("\\", "/"),
block: SiteBuilder.() -> Unit,
) {
contract {