More embed stuff

This commit is contained in:
kageru 2020-03-12 10:57:28 +01:00
parent 8e5becc777
commit dfe048bac2
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 16 additions and 13 deletions

@ -132,7 +132,7 @@ object Routes {
if (raw) { if (raw) {
respondText(paste.content, ContentType.Text.Plain) respondText(paste.content, ContentType.Text.Plain)
} else { } else {
respond(HttpStatusCode.OK, PastePage.build(paste.content, ext)) respond(HttpStatusCode.OK, PastePage.build(paste.content, paste.uri, ext))
} }
} ?: respond(HttpStatusCode.NotFound, "nothing found for id $uri") } ?: respond(HttpStatusCode.NotFound, "nothing found for id $uri")
} }

@ -10,10 +10,7 @@ object AboutPage {
private val domain = "${config[ServerSpec.domain]}" private val domain = "${config[ServerSpec.domain]}"
val content = HtmlContent(HttpStatusCode.OK) { val content = HtmlContent(HttpStatusCode.OK) {
head { head {
link(rel = "stylesheet", href = "/style.css", type = "text/css") defaultHead("About kodeshare")
meta(content = "About Kodeshare – a FOSS [ph]astebin alternative") {
attributes["property"] = "og:title"
}
} }
body { body {
div("wrapper") { div("wrapper") {

@ -7,10 +7,7 @@ import kotlinx.html.*
object Homepage { object Homepage {
val content = HtmlContent(HttpStatusCode.OK) { val content = HtmlContent(HttpStatusCode.OK) {
head { head {
link(rel = "stylesheet", href = "/style.css", type = "text/css") defaultHead("Create new paste")
meta(content = "Kodeshare – a FOSS [ph]astebin alternative") {
attributes["property"] = "og:title"
}
} }
body { body {
a("/about") { div(Css.FLOATY_CLASS) { +"About" } } a("/about") { div(Css.FLOATY_CLASS) { +"About" } }
@ -29,3 +26,14 @@ object Homepage {
} }
} }
} }
fun HEAD.defaultHead(title: String) {
link(rel = "stylesheet", href = "/style.css", type = "text/css")
meta(content = title) {
attributes["property"] = "og:title"
}
meta(content = "kodeshare – a FOSS pastebin alternative") {
attributes["property"] = "og:site_name"
}
meta(name = "theme-color", content = "#66D9EF")
}

@ -4,7 +4,7 @@ import io.ktor.html.HtmlContent
import kotlinx.html.* import kotlinx.html.*
object PastePage { object PastePage {
fun build(content: String, type: String?) = HtmlContent { fun build(content: String, uri: String, type: String?) = HtmlContent {
head { head {
link(rel = "stylesheet", href = "/style.css", type = "text/css") link(rel = "stylesheet", href = "/style.css", type = "text/css")
link( link(
@ -13,9 +13,7 @@ object PastePage {
type = "text/css" type = "text/css"
) )
script(src = "https://p.kageru.moe/static/hl.js") {} script(src = "https://p.kageru.moe/static/hl.js") {}
meta(content = "Kodeshare – a FOSS [ph]astebin alternative") { defaultHead("View paste $uri${type?.let { " (type $it)" } ?: ""}")
attributes["property"] = "og:title"
}
// Show the first 3 lines in preview/embed for applications like discord, slack, or skype // Show the first 3 lines in preview/embed for applications like discord, slack, or skype
meta(content = content.lines().take(3).joinToString("\n")) { meta(content = content.lines().take(3).joinToString("\n")) {
attributes["property"] = "og:description" attributes["property"] = "og:description"