Skip to content

Commit

Permalink
Added the feature to add social media icons to the root container tem…
Browse files Browse the repository at this point in the history
…plate using the configuration. (#39)
  • Loading branch information
tscholze authored Dec 30, 2022
2 parents 307d105 + e222fb8 commit a1bef91
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 241 deletions.
199 changes: 0 additions & 199 deletions __styles/air.css

This file was deleted.

23 changes: 0 additions & 23 deletions __styles/latex.css

This file was deleted.

33 changes: 21 additions & 12 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import io.github.tscholze.kotlog.Kotlog
import io.github.tscholze.kotlog.models.BlogConfiguration
import io.github.tscholze.kotlog.models.SocialMedia
import io.github.tscholze.kotlog.models.SocialMediaPlatform

fun main(args: Array<String>) {

// 1. Create a configuration for the blog,
// or it will be fetched from `~/.kotlog file`
//
// Sample:

// val configuration = BlogConfiguration(
// baseUrl = "https://tscholze.github.io/blog",
// titleText = "Tobias Scholze | The Stuttering Nerd",
// footerText = "Made with ❤️ without JavaScript| Kotlog | Tobias Scholze",
// outputDirectoryName = "www"
//)
// 1.1
// fetched from `~/.kotlog file`
//
// 1.2.
// Use a configuration object in code.
val configuration = BlogConfiguration(
baseUrl = "https://tscholze.github.io/blog",
titleText = "Tobias Scholze | The Stuttering Nerd",
footerText = "Made with ❤️ without JavaScript| Kotlog | Tobias Scholze",
outputDirectoryName = "www",
socialMedia = listOf(
SocialMedia(SocialMediaPlatform.GITHUB, "tscholze"),
SocialMedia(SocialMediaPlatform.TWITTER, "tobonautilus"),
SocialMedia(SocialMediaPlatform.MASTODON, "@tobonaut@mastodon.social", "https://mastodon.social/@tobonaut")
)
)

// 2. Call and run Kotlog with command line arguments and configuration.
Kotlog(args)
}

Kotlog(args, configuration)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.github.tscholze.kotlog.models

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonNames

/**
* Defines the blog layout
Expand All @@ -12,6 +10,7 @@ import kotlinx.serialization.json.JsonNames
* @property footerText Footer text of the blog
* @property outputDirectoryName The output were the generated content should be placed
* @property youtubeKey YouTube API Key, default value is empty string.
* @property socialMedia List of social media platforms that the blog owner is using, default value is empty
*/
@Serializable
data class BlogConfiguration(
Expand All @@ -20,4 +19,48 @@ data class BlogConfiguration(
val footerText: String,
val outputDirectoryName: String,
val youtubeKey: String = "",
)
val socialMedia: List<SocialMedia> = emptyList()
)

/**
* Describes a social media platform entry.
*
* @property platform Social media platform
* @property id Your ID, username or other name
* @property payload Optional payload used per platform
*/
@Serializable
data class SocialMedia(
val platform: SocialMediaPlatform,
val id: String,
val payload: String? = null
)

/**
* List of all supported and render-able social media
* platforms.
*/
@Serializable
enum class SocialMediaPlatform {
/**
* twitter.com
*
* Use your handle with without the @ as id
*/
TWITTER,

/**
* mastodon
*
* Use payload property to add your verification link
*/
MASTODON,

/**
* github.com
*
* Use your username as id.
*/
GITHUB
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class RootContainer (
private val contentHtml: String
): Renderable {

// MARK: - Renderable -

// MARK: - Render-able -
override fun render(): String {
val icons = SocialMediaIcons(configuration.socialMedia).render()

return """<!doctype html>
<html class="no-js" lang="">
Expand All @@ -42,6 +43,8 @@ class RootContainer (
<link rel="icon" href="icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous" />
<link rel="stylesheet" href="style.css">
</head>
Expand All @@ -56,7 +59,7 @@ class RootContainer (
<footer>
<hr />
${configuration.footerText}
${configuration.footerText} | $icons
</footer>
</html>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.tscholze.kotlog.templates.components

import io.github.tscholze.kotlog.models.SocialMedia
import io.github.tscholze.kotlog.models.SocialMediaPlatform
import io.github.tscholze.kotlog.templates.Renderable

/**
* Renders a linked social media icon.
*
* @param socialMedia Social media entry.
*/
class SocialMediaIcon(private val socialMedia: SocialMedia): Renderable {
override fun render(): String {
return when(socialMedia.platform) {
SocialMediaPlatform.GITHUB -> "<a href=\"https://github.com/${socialMedia.id}\" title=\"GitHub\" target=\"_bank\"><i class=\"fab fa-github\"></i></a>"
SocialMediaPlatform.MASTODON -> "<a rel=\"me\" href=\"${socialMedia.payload ?: ""}\" title=\"Mastodon\" target=\"_bank\"><i class=\"fab fa-mastodon\"></i></a>"
SocialMediaPlatform.TWITTER -> "<a href=\"https://twitter.com/${socialMedia.id}\" title=\"Twitter\" target=\"_bank\"><i class=\"fab fa-twitter\"></i></a>"
}
}
}

/**
* Renders a space separated row of linked social media icons.
*
* @param socialMedias List of social media entries.
*/
class SocialMediaIcons(private val socialMedias: List<SocialMedia>): Renderable {
override fun render(): String {
return socialMedias
.map { SocialMediaIcon(it).render() }
.joinToString(" ") { it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Index(
private val snippets: List<SnippetConfiguration>
): Renderable {

// MARK: - Renderable -
// MARK: - Render-able -

override fun render(): String {

Expand Down

0 comments on commit a1bef91

Please sign in to comment.