Skip to content

Commit

Permalink
chore: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LichtHund committed Jul 7, 2024
1 parent 5eb41f3 commit 54453fc
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 121 deletions.
5 changes: 1 addition & 4 deletions backend/src/main/kotlin/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.triumphteam.backend
import dev.triumphteam.backend.api.apiRoutes
import dev.triumphteam.backend.api.auth.TriumphPrincipal
import dev.triumphteam.backend.meilisearch.Meili
import dev.triumphteam.backend.website.pages.respondNotFound
import dev.triumphteam.backend.website.websiteRoutes
import dev.triumphteam.website.JsonSerializer
import io.ktor.http.CacheControl
Expand All @@ -17,7 +16,6 @@ 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.html.respondHtml
import io.ktor.server.http.content.staticFiles
import io.ktor.server.http.content.staticResources
import io.ktor.server.plugins.cachingheaders.CachingHeaders
Expand All @@ -30,7 +28,6 @@ import io.ktor.server.plugins.forwardedheaders.XForwardedHeaders
import io.ktor.server.plugins.statuspages.StatusPages
import io.ktor.server.resources.Resources
import io.ktor.server.response.respondRedirect
import io.ktor.server.response.respondText
import io.ktor.server.routing.routing

/** Module of the application. */
Expand All @@ -44,7 +41,7 @@ public fun Application.module() {
}

install(StatusPages) {
status(HttpStatusCode.NotFound) { call, status ->
status(HttpStatusCode.NotFound) { call, _ ->
call.respondRedirect("/404")
}
}
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/kotlin/meilisearch/MeiliClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class MeiliClient(
) {

/** Create the index. Success even if it already exists. */
public suspend fun create(): HttpResponse = client.post(Indexes()) {
private suspend fun create(): HttpResponse = client.post(Indexes()) {
contentType(ContentType.Application.Json)
setBody(Create(uid, primaryKey))
}.also {
Expand Down Expand Up @@ -124,14 +124,14 @@ public class MeiliClient(
public suspend fun transferTo(index: Index): HttpResponse {
val createResponse = index.create()

// If there was an error creating the new index we return the response
// If there was an error creating the new index, we return the response
if (!createResponse.status.isSuccess()) return createResponse

val swapResponse = client.post(Indexes.Swap()) {
setBody(listOf(Swap(listOf(uid, this@Index.uid))))
}

// If there was an error swapping the new indexes we return the response
// If there was an error swapping the new indexes, we return the response
if (!swapResponse.status.isSuccess()) return swapResponse

// Then we delete the current index
Expand Down Expand Up @@ -166,7 +166,7 @@ public class MeiliClient(
public class Swap(public val parent: Indexes = Indexes())
}

/** Serializable class for the create end point. */
/** Serializable class for the "create" end point. */
@Serializable
public data class Create(
val uid: String,
Expand Down
16 changes: 0 additions & 16 deletions backend/src/main/kotlin/meilisearch/MeiliPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ package dev.triumphteam.backend.meilisearch

import io.ktor.http.URLProtocol
import io.ktor.server.application.Application
import io.ktor.server.application.ApplicationCall
import io.ktor.server.application.BaseApplicationPlugin
import io.ktor.server.application.application
import io.ktor.server.application.plugin
import io.ktor.util.AttributeKey
import io.ktor.util.pipeline.PipelineContext

public class Meili(config: Configuration) {

Expand All @@ -31,15 +27,3 @@ public class Meili(config: Configuration) {
}
}
}

public suspend inline fun <reified T> PipelineContext<*, ApplicationCall>.search(
index: String,
query: String,
limit: Int = 20,
filter: String? = null,
): List<T> = with(this.application.plugin(Meili).client) {
return index(index).search(query, limit, filter)
}

public suspend inline fun PipelineContext<*, ApplicationCall>.index(index: String): MeiliClient.Index =
application.plugin(Meili).client.index(index)
File renamed without changes.
4 changes: 1 addition & 3 deletions backend/src/main/kotlin/website/pages/NotFound.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package dev.triumphteam.backend.website.pages

import kotlinx.css.h1
import kotlinx.html.HTML
import kotlinx.html.body
import kotlinx.html.classes
import kotlinx.html.div
import kotlinx.html.h1
import kotlinx.html.meta
import kotlinx.html.title
Expand All @@ -18,7 +16,7 @@ public fun HTML.respondNotFound(developmentMode: Boolean) {

meta {
name = "og:title"
content = "TriumphTeam"
content = "TriumphTeam | Not Found"
}

meta {
Expand Down
80 changes: 42 additions & 38 deletions backend/src/main/kotlin/website/pages/docs/DocsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private fun HTML.renderFullPage(
src = "https://unpkg.com/[email protected]"
}

val title = "TrimphTeam | ${project.name} - ${currentPage.title}"
val title = "TriumphTeam | ${project.name} - ${currentPage.title}"
// TODO: Replace with final URL, sucks that it can't be relative
val image = "https://new.triumphteam.dev/assets/${project.id}/${version.reference}/${currentPage.id}/banner.png"

Expand Down Expand Up @@ -228,43 +228,47 @@ private fun HTML.renderFullPage(
title { +title }

style {
+CssBuilder().apply {
rule(".project-color-bg") {
backgroundColor = Color(project.color)
}

rule(".project-color") {
color = Color(project.color)
}

rule(".project-color-hover") {
transitionDuration = 0.3.s
}

rule(".project-color-border") {
transitionDuration = 0.3.s
}

rule(".project-color-hover:hover") {
color = Color(project.color)
}

rule(".project-color-border:hover") {
borderColor = Color(project.color)
}

rule(".docs-content a") {
color = Color(project.color)
transitionDuration = 0.3.s
}
rule(".docs-content a:hover") {
color = Color("${project.color}C8")
}

rule(".summary-active *") {
color = Color(project.color)
}
}.toString()
unsafe {
raw(
CssBuilder().apply {
rule(".project-color-bg") {
backgroundColor = Color(project.color)
}

rule(".project-color") {
color = Color(project.color)
}

rule(".project-color-hover") {
transitionDuration = 0.3.s
}

rule(".project-color-border") {
transitionDuration = 0.3.s
}

rule(".project-color-hover:hover") {
color = Color(project.color)
}

rule(".project-color-border:hover") {
borderColor = Color(project.color)
}

rule(".docs-content a") {
color = Color(project.color)
transitionDuration = 0.3.s
}
rule(".docs-content a:hover") {
color = Color("${project.color}C8")
}

rule(".summary-active *") {
color = Color(project.color)
}
}.toString()
)
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions backend/src/main/kotlin/website/pages/docs/resource/Docs.kt

This file was deleted.

6 changes: 0 additions & 6 deletions docs/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import io.ktor.http.Headers
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.kotlinx.json.json
import io.ktor.util.InternalAPI
import net.lingala.zip4j.ZipFile
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.Option
Expand Down Expand Up @@ -67,7 +66,6 @@ private val mdParser = Parser.builder()

private val logger: Logger = LoggerFactory.getLogger("docs")

@OptIn(InternalAPI::class)
public suspend fun main(args: Array<String>) {

val options = DefaultParser().parse(
Expand Down Expand Up @@ -274,8 +272,4 @@ private data class Projects(val projects: List<ProjectWithIcon>) {
fun toRepository(): Repository {
return Repository(projects.map(ProjectWithIcon::project))
}

fun icons(): List<File> {
return projects.map(ProjectWithIcon::icon)
}
}
2 changes: 1 addition & 1 deletion docs/src/main/kotlin/markdown/FenceBlockParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class FenceBlockParser(private val skipCharacter: Char) : Abstra
line[nextNonSpace] == skipCharacter &&
isClosing(line, nextNonSpace)
) {
// closing fence - we're at end of line, so we can finalize now
// closing "fence" - we're at the end of line, so we can finalize now
return BlockContinue.finished()
}

Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/kotlin/markdown/MarkdownRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public class MarkdownRenderer(private val context: HtmlNodeRendererContext) : Ab
}

override fun visit(orderedList: OrderedList) {
val start = orderedList.startNumber
val start = orderedList.markerStartNumber
val attrs: MutableMap<String, String> = LinkedHashMap()
if (start != 1) {
attrs["start"] = start.toString()
Expand Down Expand Up @@ -309,9 +309,9 @@ public class MarkdownRenderer(private val context: HtmlNodeRendererContext) : Ab
private fun isInTightList(paragraph: Paragraph): Boolean {
val parent: Node? = paragraph.parent
if (parent != null) {
val gramps = parent.parent
if (gramps is ListBlock) {
return gramps.isTight
val grandParent = parent.parent
if (grandParent is ListBlock) {
return grandParent.isTight
}
}
return false
Expand Down
36 changes: 0 additions & 36 deletions docs/src/main/kotlin/markdown/highlight/CodeHighlight.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class LanguageDefinition(
}
}

public fun captureHighlights(code: String): Map<Int, Collection<HighlightStep>> {
private fun captureHighlights(code: String): Map<Int, Collection<HighlightStep>> {
val highlights = components.flatMap { it.highlight(code) }.toMutableList()

globalValidator.forEach { validator ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MultilineCommentHighlighter : LanguageHighlightComponent {
if (char == ASTERISK) {
asteriskIndex = index

// Previous was a slash, no it's asterisk, we found an "opener"
// Previous was a slash, no it's asterisk, we found an "opener".
if (slashIndex + 1 == index) {
openerIndex = slashIndex
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class StringHighlighter(
return@forEachIndexed
}

// If we find end of line reset since it's not allowed
// If we find the end of line reset since it's not allowed
if (char.isNewLine()) {
openerIndex = INVALID_INDEX
}
Expand Down

0 comments on commit 54453fc

Please sign in to comment.