diff --git a/build.gradle.kts b/build.gradle.kts index b5af7ac..5fb6820 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { implementation("io.ktor:ktor-server-host-common:$ktorVersion") implementation("io.ktor:ktor-server-status-pages:$ktorVersion") implementation("io.ktor:ktor-server-netty:$ktorVersion") + implementation("io.ktor:ktor-server-http-redirect:$ktorVersion") implementation("ch.qos.logback:logback-classic:1.2.11") implementation("space.kscience:dataforge-workspace:$dataforgeVersion") implementation("space.kscience:dataforge-io-yaml:$dataforgeVersion") diff --git a/src/main/kotlin/ru/mipt/spc/Application.kt b/src/main/kotlin/ru/mipt/spc/Application.kt index decec03..84b3fe8 100644 --- a/src/main/kotlin/ru/mipt/spc/Application.kt +++ b/src/main/kotlin/ru/mipt/spc/Application.kt @@ -1,7 +1,9 @@ package ru.mipt.spc import io.ktor.server.application.Application +import io.ktor.server.application.install import io.ktor.server.application.log +import io.ktor.server.plugins.httpsredirect.HttpsRedirect import kotlinx.css.CssBuilder import kotlinx.html.CommonAttributeGroupFacade import kotlinx.html.style @@ -47,6 +49,8 @@ const val BUILD_DATE_FILE = "/buildDate" @Suppress("unused") fun Application.spcModule() { + install(HttpsRedirect) + val context = Context("spc-site") { plugin(SnarkPlugin) } diff --git a/src/main/kotlin/space/kscience/snark/SiteData.kt b/src/main/kotlin/space/kscience/snark/SiteData.kt index e62451e..981ca2d 100644 --- a/src/main/kotlin/space/kscience/snark/SiteData.kt +++ b/src/main/kotlin/space/kscience/snark/SiteData.kt @@ -37,7 +37,7 @@ data class SiteData( return SiteData(snark, emptyData, baseUrlPath, meta) } - const val INDEX_PAGE_TOKEN: String = "index" + val INDEX_PAGE_TOKEN: NameToken = NameToken("index") } } @@ -53,8 +53,9 @@ fun SiteData.resolveRef(name: String): String = if (baseUrlPath.isEmpty()) { /** * Resolve a page designated by given name. Depending on rendering specifics, some prefixes or suffixes could be added. */ -fun SiteData.resolvePage(name: Name): String = - resolveRef(name.tokens.joinToString("/")) + (meta["pageSuffix"].string ?: "") +fun SiteData.resolvePage(name: Name): String { + return resolveRef(name.tokens.joinToString("/")) + (meta["pageSuffix"].string ?: "") +} /** * diff --git a/src/main/kotlin/space/kscience/snark/StaticSiteBuilder.kt b/src/main/kotlin/space/kscience/snark/StaticSiteBuilder.kt index 038a507..c580fa1 100644 --- a/src/main/kotlin/space/kscience/snark/StaticSiteBuilder.kt +++ b/src/main/kotlin/space/kscience/snark/StaticSiteBuilder.kt @@ -73,7 +73,7 @@ fun SnarkPlugin.static(path: Path, block: SiteBuilder.() -> Unit) { this, baseUrlPath = path.absolutePathString(), meta = Meta { - "pageSuffix" put "/index.html" + "pageSuffix" put ".html" } ) StaticSiteBuilder(base, path).block()