Skip to content

Commit

Permalink
chore: General fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LichtHund committed Jun 26, 2024
1 parent 694f326 commit 8c4c37a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
10 changes: 8 additions & 2 deletions backend/src/main/kotlin/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. */
Expand Down Expand Up @@ -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 ->
Expand Down
21 changes: 12 additions & 9 deletions backend/src/main/kotlin/api/ProjectSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 4 additions & 0 deletions backend/src/main/kotlin/api/database/Entities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public object Pages : IdTable<String>("pages") {
public val version: Column<EntityID<String>> =
reference("version_id", DocVersions, ReferenceOption.CASCADE, ReferenceOption.CASCADE)
public val content: Column<String> = text("content")
public val title: Column<String> = text("title")
public val subTitle: Column<String> = text("sub_title")
public val summary: Column<PageSummary> = serializable<PageSummary>("summary")

override val primaryKey: PrimaryKey = PrimaryKey(id)
Expand Down Expand Up @@ -64,5 +66,7 @@ public class PageEntity(id: EntityID<String>) : Entity<String>(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
}
12 changes: 9 additions & 3 deletions backend/src/main/kotlin/website/pages/docs/DocsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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 }
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion docs/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public suspend fun main(args: Array<String>) {
}

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!")
Expand Down

0 comments on commit 8c4c37a

Please sign in to comment.