Skip to content

Commit a1bef91

Browse files
authored
Added the feature to add social media icons to the root container template using the configuration. (#39)
2 parents 307d105 + e222fb8 commit a1bef91

File tree

7 files changed

+107
-241
lines changed

7 files changed

+107
-241
lines changed

__styles/air.css

Lines changed: 0 additions & 199 deletions
This file was deleted.

__styles/latex.css

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/kotlin/Main.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import io.github.tscholze.kotlog.Kotlog
2+
import io.github.tscholze.kotlog.models.BlogConfiguration
3+
import io.github.tscholze.kotlog.models.SocialMedia
4+
import io.github.tscholze.kotlog.models.SocialMediaPlatform
25

36
fun main(args: Array<String>) {
47

58
// 1. Create a configuration for the blog,
6-
// or it will be fetched from `~/.kotlog file`
7-
//
8-
// Sample:
99

10-
// val configuration = BlogConfiguration(
11-
// baseUrl = "https://tscholze.github.io/blog",
12-
// titleText = "Tobias Scholze | The Stuttering Nerd",
13-
// footerText = "Made with ❤️ without JavaScript| Kotlog | Tobias Scholze",
14-
// outputDirectoryName = "www"
15-
//)
10+
// 1.1
11+
// fetched from `~/.kotlog file`
12+
//
13+
// 1.2.
14+
// Use a configuration object in code.
15+
val configuration = BlogConfiguration(
16+
baseUrl = "https://tscholze.github.io/blog",
17+
titleText = "Tobias Scholze | The Stuttering Nerd",
18+
footerText = "Made with ❤️ without JavaScript| Kotlog | Tobias Scholze",
19+
outputDirectoryName = "www",
20+
socialMedia = listOf(
21+
SocialMedia(SocialMediaPlatform.GITHUB, "tscholze"),
22+
SocialMedia(SocialMediaPlatform.TWITTER, "tobonautilus"),
23+
SocialMedia(SocialMediaPlatform.MASTODON, "@[email protected]", "https://mastodon.social/@tobonaut")
24+
)
25+
)
1626

1727
// 2. Call and run Kotlog with command line arguments and configuration.
18-
Kotlog(args)
19-
}
20-
28+
Kotlog(args, configuration)
29+
}
Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.github.tscholze.kotlog.models
22

3-
import kotlinx.serialization.ExperimentalSerializationApi
43
import kotlinx.serialization.Serializable
5-
import kotlinx.serialization.json.JsonNames
64

75
/**
86
* Defines the blog layout
@@ -12,6 +10,7 @@ import kotlinx.serialization.json.JsonNames
1210
* @property footerText Footer text of the blog
1311
* @property outputDirectoryName The output were the generated content should be placed
1412
* @property youtubeKey YouTube API Key, default value is empty string.
13+
* @property socialMedia List of social media platforms that the blog owner is using, default value is empty
1514
*/
1615
@Serializable
1716
data class BlogConfiguration(
@@ -20,4 +19,48 @@ data class BlogConfiguration(
2019
val footerText: String,
2120
val outputDirectoryName: String,
2221
val youtubeKey: String = "",
23-
)
22+
val socialMedia: List<SocialMedia> = emptyList()
23+
)
24+
25+
/**
26+
* Describes a social media platform entry.
27+
*
28+
* @property platform Social media platform
29+
* @property id Your ID, username or other name
30+
* @property payload Optional payload used per platform
31+
*/
32+
@Serializable
33+
data class SocialMedia(
34+
val platform: SocialMediaPlatform,
35+
val id: String,
36+
val payload: String? = null
37+
)
38+
39+
/**
40+
* List of all supported and render-able social media
41+
* platforms.
42+
*/
43+
@Serializable
44+
enum class SocialMediaPlatform {
45+
/**
46+
* twitter.com
47+
*
48+
* Use your handle with without the @ as id
49+
*/
50+
TWITTER,
51+
52+
/**
53+
* mastodon
54+
*
55+
* Use payload property to add your verification link
56+
*/
57+
MASTODON,
58+
59+
/**
60+
* github.com
61+
*
62+
* Use your username as id.
63+
*/
64+
GITHUB
65+
}
66+

src/main/kotlin/io/github/tscholze/kotlog/templates/components/RootContainer.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class RootContainer (
1919
private val contentHtml: String
2020
): Renderable {
2121

22-
// MARK: - Renderable -
23-
22+
// MARK: - Render-able -
2423
override fun render(): String {
24+
val icons = SocialMediaIcons(configuration.socialMedia).render()
25+
2526
return """<!doctype html>
2627
<html class="no-js" lang="">
2728
@@ -42,6 +43,8 @@ class RootContainer (
4243
<link rel="icon" href="icon.svg" type="image/svg+xml">
4344
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
4445
46+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"
47+
integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous" />
4548
<link rel="stylesheet" href="style.css">
4649
</head>
4750
@@ -56,7 +59,7 @@ class RootContainer (
5659
5760
<footer>
5861
<hr />
59-
${configuration.footerText}
62+
${configuration.footerText} | $icons
6063
</footer>
6164
6265
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.github.tscholze.kotlog.templates.components
2+
3+
import io.github.tscholze.kotlog.models.SocialMedia
4+
import io.github.tscholze.kotlog.models.SocialMediaPlatform
5+
import io.github.tscholze.kotlog.templates.Renderable
6+
7+
/**
8+
* Renders a linked social media icon.
9+
*
10+
* @param socialMedia Social media entry.
11+
*/
12+
class SocialMediaIcon(private val socialMedia: SocialMedia): Renderable {
13+
override fun render(): String {
14+
return when(socialMedia.platform) {
15+
SocialMediaPlatform.GITHUB -> "<a href=\"https://github.com/${socialMedia.id}\" title=\"GitHub\" target=\"_bank\"><i class=\"fab fa-github\"></i></a>"
16+
SocialMediaPlatform.MASTODON -> "<a rel=\"me\" href=\"${socialMedia.payload ?: ""}\" title=\"Mastodon\" target=\"_bank\"><i class=\"fab fa-mastodon\"></i></a>"
17+
SocialMediaPlatform.TWITTER -> "<a href=\"https://twitter.com/${socialMedia.id}\" title=\"Twitter\" target=\"_bank\"><i class=\"fab fa-twitter\"></i></a>"
18+
}
19+
}
20+
}
21+
22+
/**
23+
* Renders a space separated row of linked social media icons.
24+
*
25+
* @param socialMedias List of social media entries.
26+
*/
27+
class SocialMediaIcons(private val socialMedias: List<SocialMedia>): Renderable {
28+
override fun render(): String {
29+
return socialMedias
30+
.map { SocialMediaIcon(it).render() }
31+
.joinToString(" ") { it }
32+
}
33+
}

src/main/kotlin/io/github/tscholze/kotlog/templates/html/Index.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Index(
1111
private val snippets: List<SnippetConfiguration>
1212
): Renderable {
1313

14-
// MARK: - Renderable -
14+
// MARK: - Render-able -
1515

1616
override fun render(): String {
1717

0 commit comments

Comments
 (0)