diff --git a/.gitignore b/.gitignore index f2dd8e6..1d4a4cd 100644 --- a/.gitignore +++ b/.gitignore @@ -72,4 +72,5 @@ gradle-app.setting classes .DS_Store .idea/libraries-with-intellij-classes.xml -dist/v*.json +dist/ +!dist/favicon.ico diff --git a/build.gradle b/build.gradle index cad344c..a264a17 100644 --- a/build.gradle +++ b/build.gradle @@ -16,5 +16,6 @@ group = "io.github.wulkanowy" allprojects { repositories { mavenCentral() + maven { url "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven" } } } diff --git a/dist/favicon.ico b/dist/favicon.ico new file mode 100644 index 0000000..be2e1e9 Binary files /dev/null and b/dist/favicon.ico differ diff --git a/dist/index.html b/dist/index.html deleted file mode 100644 index c37c26b..0000000 --- a/dist/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Wulkanowy Messages - - - Open v1.json - - diff --git a/generator/build.gradle b/generator/build.gradle index bac054d..8153646 100644 --- a/generator/build.gradle +++ b/generator/build.gradle @@ -10,6 +10,7 @@ mainClassName = 'MainKt' dependencies { implementation project(":pojos") implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0" + implementation "org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2" testImplementation platform("org.junit:junit-bom:5.8.1") testImplementation "org.junit.jupiter:junit-jupiter" diff --git a/generator/src/main/kotlin/html.kt b/generator/src/main/kotlin/html.kt new file mode 100644 index 0000000..99c840e --- /dev/null +++ b/generator/src/main/kotlin/html.kt @@ -0,0 +1,43 @@ +import io.github.wulkanowy.messages.pojo.Message +import kotlinx.html.* +import kotlinx.html.stream.appendHTML +import java.time.LocalDate + +fun generateHtml(messages: List): String = buildString { + appendLine("") + appendHTML().html { + lang = "pl" + head { + meta { charset = "UTF-8" } + title("Wulkanowy Messages") + } + body { + h1 { +"Wulkanowy Messages" } + ul { + messages.forEach { + li { + b { + +"${it.id}. " + if (!it.destinationUrl.isNullOrBlank()) { + a(it.destinationUrl) { + +it.title + } + } else +it.title + } + br + span { + +it.content + } + } + } + } + footer { + +"© ${LocalDate.now().year} by Wulkanowy | " + +"wygenerowano ${LocalDate.now()} | " + a("v1.json") { + +"raw json" + } + } + } + } +} diff --git a/generator/src/main/kotlin/main.kt b/generator/src/main/kotlin/main.kt index 7baddb6..e421350 100644 --- a/generator/src/main/kotlin/main.kt +++ b/generator/src/main/kotlin/main.kt @@ -2,10 +2,16 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import java.io.File +private val json = Json { + encodeDefaults = true +} + fun main() { checkIdUniqueness(messages) - val json = Json.encodeToString(messages) + val json = json.encodeToString(messages) + val html = generateHtml(messages) File("../dist/v1.json").writeText(json) + File("../dist/index.html").writeText(html) }