-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcreate-episode.kts
executable file
Β·169 lines (134 loc) Β· 6.38 KB
/
create-episode.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env kscript
@file:DependsOn("info.picocli:picocli:4.3.2")
import picocli.CommandLine
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import picocli.CommandLine.Parameters
import java.io.File
import java.nio.file.*
import java.util.concurrent.Callable
import java.time.*
import java.time.format.*
import java.util.concurrent.*
@Command(name = "create-episode", mixinStandardHelpOptions = true, version = ["1.0"])
class GenerateSnippets : Callable<Int> {
@Option(names = ["-p", "--project"], required = true, description = ["Name of the project to spotlight"])
private var project: String = ""
@Option(names = ["-g", "--guest"], required = true, description = ["Name of the guest"])
private var guest: String = ""
@Option(names = ["-d", "--date"], required = true, description = ["Release date of the episode"])
private var date: String = ""
@Option(names = ["-n", "--number"], required = true, description = ["Number of the episode"])
private var number: Int = 0
override fun call(): Int {
info("πππ create-episode βοΈβοΈβοΈοΈοΈοΈ", "")
info("Welcome to create-episode", "π")
info("Creating your episode...", "")
val id = project.toLowerCase().replace(" ", "-")
val guestId = guest.toLowerCase().replace(" ", "-")
val threeDigitNumber = "%03d".format(number)
val filename = "./_posts/$date-$threeDigitNumber-$id.md"
val imageFolder = "./assets/images/episodes/"
// language=YAML
val content = """
---
title: "#$number - $project with $guest"
excerpt: "TODO"
author_profile: true
description: "TODO"
header:
teaser: "/assets/images/header-single-episode.png"
overlay_image: "/assets/images/header-single-episode.png"
show_overlay_excerpt: false
overlay_filter: "0.6"
og_image: "/assets/images/episodes/$number-cover.png"
date: $date
permalink: /$number/
redirect_from:
- /$number/$id/
- /$number/$id-with-$guestId/
podcast_image: "/assets/images/episodes/$number-cover.png"
podcast_episode_number: $number
podcast_link: https://dts.podtrac.com/redirect.m4a/hosting.thebakery.dev/$number-thedevelopersbakery-$id.m4a
podcast_duration: "TODO"
podcast_length: TODO
---
<!-- <iframe src="https://open.spotify.com/embed-podcast/show/4jV6Yoz7D38sZJlYMzJm3k" width="100%" height="232" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe> -->
Enjoy the show π¨βπ³
# Show Notes
- **00.00** Intro
# Resources
* <i class="fab fa-github"></i> [cortinico/thebakery on GitHub](https://github.com/cortinico/thebakery)
* <i class="fas fa-link"></i> [TheBakery Official Website](https://thebakery.dev/)
* Mentioned Resources:
* <i class="fas fa-link"></i> [A website](https://ncorti.com/)
* <i class="fab fa-github"></i> [@cortinico on GitHub](https://github.com/cortinico)
* <i class="fab fa-twitter"></i> [@cortinico on Twitter](https://twitter.com/cortinico)
# Show links
* <i class="fas fa-link"></i> [Podcast Website](https://thebakery.dev)
* <i class="fab fa-spotify"></i> [The Developers' Bakery on Spotify](https://open.spotify.com/show/4jV6Yoz7D38sZJlYMzJm3k?si=AL3ske_0R_CKlEScMhYhug)
* <i class="fas fa-podcast"></i> [The Developers' Bakery on Apple Podcasts](https://podcasts.apple.com/us/podcast/the-developers-bakery/id1542849034)
* <i class="fab fa-google-play"></i> [The Developers' Bakery on Google Podcasts](https://podcasts.google.com/feed/aHR0cHM6Ly90aGViYWtlcnkuZGV2L3BvZGNhc3QueG1s)
* <i class="fab fa-twitter"></i> [@thebakerydev on Twitter](https://twitter.com/thebakerydev)
* <i class="fab fa-twitter"></i> [@cortinico on Twitter](https://twitter.com/cortinico)
""".trimIndent()
File(filename).writeText(content)
info("Podcast project title: $project", "")
info("Podcast guest: $guest", "")
info("Podcast date: $date", "")
info("Podcast number: $number", "")
succ("Episode created successfully: $filename")
return 0
}
/*
* DEBUG Prints function
******************************************************************/
fun error(message: String, throwable: Throwable? = null, statusCode: Int = 1): Nothing {
System.err.println("β\t${Colors.ANSI_RED}$message${Colors.ANSI_RESET}")
throwable?.let {
System.err.print(Colors.ANSI_RED)
it.printStackTrace()
System.err.print(Colors.ANSI_RESET)
}
System.exit(statusCode)
throw Error()
}
fun warn(message: String) {
System.out.println("β οΈ\t${Colors.ANSI_YELLOW}$message${Colors.ANSI_RESET}")
}
fun succ(message: String) {
System.out.println("β
\t${Colors.ANSI_GREEN}$message${Colors.ANSI_RESET}")
}
fun info(message: String, emoji: String = "βΉοΈ") {
System.out.println("$emoji\t$message")
}
fun String.runCommand(
workingDir: File = File("."),
timeoutAmount: Long = 60
): String? = try {
ProcessBuilder(split("\\s".toRegex()))
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start().apply { waitFor(timeoutAmount, TimeUnit.SECONDS) }
.inputStream.bufferedReader().readText()
} catch (e: java.io.IOException) {
e.printStackTrace()
null
}
}
CommandLine(GenerateSnippets()).execute(*args)
/*
* ASCII Color
******************************************************************/
object Colors {
val ANSI_RESET = "\u001B[0m"
val ANSI_BLACK = "\u001B[30m"
val ANSI_RED = "\u001B[31m"
val ANSI_GREEN = "\u001B[32m"
val ANSI_YELLOW = "\u001B[33m"
val ANSI_BLUE = "\u001B[34m"
val ANSI_PURPLE = "\u001B[35m"
val ANSI_CYAN = "\u001B[36m"
val ANSI_WHITE = "\u001B[37m"
}