diff --git a/backend/src/main/kotlin/Module.kt b/backend/src/main/kotlin/Module.kt index 5344617..1d40dc1 100644 --- a/backend/src/main/kotlin/Module.kt +++ b/backend/src/main/kotlin/Module.kt @@ -14,6 +14,7 @@ import io.ktor.server.application.Application import io.ktor.server.application.install import io.ktor.server.auth.Authentication import io.ktor.server.auth.bearer +import io.ktor.server.http.content.CompressedFileType import io.ktor.server.http.content.staticFiles import io.ktor.server.http.content.staticResources import io.ktor.server.plugins.cachingheaders.CachingHeaders @@ -24,6 +25,7 @@ import io.ktor.server.plugins.defaultheaders.DefaultHeaders import io.ktor.server.plugins.forwardedheaders.ForwardedHeaders import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders import io.ktor.server.resources.Resources +import io.ktor.server.routing.get import io.ktor.server.routing.routing /** Module of the application. */ @@ -68,8 +70,12 @@ public fun Application.module() { routing { - staticResources("/static", "static") - staticFiles("/assets", DATA_FOLDER.resolve("core")) + staticResources("/static", "static") { + preCompressed(CompressedFileType.BROTLI, CompressedFileType.GZIP) + } + staticFiles("/assets", DATA_FOLDER.resolve("core")) { + preCompressed(CompressedFileType.BROTLI, CompressedFileType.GZIP) + } install(CachingHeaders) { options { _, outgoingContent -> diff --git a/backend/src/main/kotlin/api/ProjectSetup.kt b/backend/src/main/kotlin/api/ProjectSetup.kt index 1c67893..4b1f160 100644 --- a/backend/src/main/kotlin/api/ProjectSetup.kt +++ b/backend/src/main/kotlin/api/ProjectSetup.kt @@ -3,6 +3,7 @@ package dev.triumphteam.backend.api import dev.triumphteam.backend.DATA_FOLDER import dev.triumphteam.backend.api.database.DocVersionEntity import dev.triumphteam.backend.api.database.PageEntity +import dev.triumphteam.backend.api.database.Pages.subTitle import dev.triumphteam.backend.api.database.ProjectEntity import dev.triumphteam.backend.banner.BannerMaker import dev.triumphteam.website.JsonSerializer @@ -68,20 +69,22 @@ public fun setupRepository(projects: File) { it.mkdirs() } - page.banner.apply { - bannerMaker.create( - icon = projectIcon, - group = group, - title = title, - subTitle = subTitle, - output = pageDir.resolve("banner.png"), - ) - } + val banner = page.banner + + bannerMaker.create( + icon = projectIcon, + group = banner.group, + title = banner.title, + subTitle = banner.subTitle, + output = pageDir.resolve("banner.png"), + ) PageEntity.new(page.id) { this.project = projectEntity this.version = versionEntity this.content = page.content + this.title = banner.title ?: "" + this.subTitle = banner.subTitle ?: "" this.summary = page.summary } } diff --git a/backend/src/main/kotlin/api/database/Entities.kt b/backend/src/main/kotlin/api/database/Entities.kt index 4c9f0c1..19df275 100644 --- a/backend/src/main/kotlin/api/database/Entities.kt +++ b/backend/src/main/kotlin/api/database/Entities.kt @@ -36,6 +36,8 @@ public object Pages : IdTable("pages") { public val version: Column> = reference("version_id", DocVersions, ReferenceOption.CASCADE, ReferenceOption.CASCADE) public val content: Column = text("content") + public val title: Column = text("title") + public val subTitle: Column = text("sub_title") public val summary: Column = serializable("summary") override val primaryKey: PrimaryKey = PrimaryKey(id) @@ -64,5 +66,7 @@ public class PageEntity(id: EntityID) : Entity(id) { public var project: ProjectEntity by ProjectEntity referencedOn Pages.project public var version: DocVersionEntity by DocVersionEntity referencedOn Pages.version public var content: String by Pages.content + public var title: String by Pages.title + public var subTitle: String by Pages.subTitle public var summary: PageSummary by Pages.summary } diff --git a/backend/src/main/kotlin/website/pages/docs/DocsPage.kt b/backend/src/main/kotlin/website/pages/docs/DocsPage.kt index 6e07288..6b706fc 100644 --- a/backend/src/main/kotlin/website/pages/docs/DocsPage.kt +++ b/backend/src/main/kotlin/website/pages/docs/DocsPage.kt @@ -18,6 +18,7 @@ import dev.triumphteam.website.project.SummaryEntry import io.ktor.http.HttpStatusCode import io.ktor.server.application.call import io.ktor.server.html.respondHtml +import io.ktor.server.request.path import io.ktor.server.request.uri import io.ktor.server.response.respond import io.ktor.server.response.respondRedirect @@ -102,7 +103,7 @@ private fun HTML.renderFullPage( styleLink("/static/css/docs_content.css") styleLink("/static/css/themes/one_dark.css") - val title = "TrimphTeam | ${project.name}" + val title = "TrimphTeam | ${project.name} - ${currentPage.title}" meta { name = "og:type" @@ -116,12 +117,13 @@ private fun HTML.renderFullPage( meta { name = "og:description" - content = "Bussy" + content = currentPage.subTitle } meta { name = "og:image" - content = "/banners/${project.id}/${version.reference}/${currentPage.id}/banner.png" + // TODO: Replace with final URL, sucks that it can't be relative + content = "https://new.triumphteam.dev/assets/${project.id}/${version.reference}/${currentPage.id}/banner.png" } title { +title } @@ -388,6 +390,8 @@ private fun getProject(project: String): ProjectData? { id = pageEntity.id.value, content = pageEntity.content, summary = pageEntity.summary, + title = pageEntity.title, + subTitle = pageEntity.subTitle, ) }.associateBy(Page::id), ) @@ -426,4 +430,6 @@ public data class Page( public val id: String, public val content: String, public val summary: PageSummary, + public val title: String, + public val subTitle: String, ) diff --git a/docs/src/main/kotlin/Application.kt b/docs/src/main/kotlin/Application.kt index 81659f3..5ba4aee 100644 --- a/docs/src/main/kotlin/Application.kt +++ b/docs/src/main/kotlin/Application.kt @@ -179,7 +179,7 @@ public suspend fun main(args: Array) { } if (response.status != HttpStatusCode.Accepted) { - error("Could not upload repository to backend!") + error("Could not upload repository to backend '${response.status}'!") } logger.info("Upload complete!")