2022-08-28 11:14:11 +02:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct HTMLElementsGenerator {
|
|
|
|
|
|
|
|
init() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func make(title: String, suffix: String) -> String {
|
|
|
|
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
|
|
|
}
|
2022-08-28 14:01:53 +02:00
|
|
|
|
|
|
|
// - TODO: Make link relative
|
|
|
|
func topBarWebsiteTitle(language: String) -> String {
|
|
|
|
"/\(language).html"
|
|
|
|
}
|
|
|
|
|
|
|
|
func topBarLanguageButton(_ language: String) -> String {
|
|
|
|
"<a href=\"\(language).html\">\(language)</a>"
|
|
|
|
}
|
|
|
|
|
|
|
|
func topBarNavigationLink(url: String, text: String, isActive: Bool) -> String {
|
|
|
|
"<a\(isActive ? " class=\"active\"" : "") href=\"/\(url)\">\(text)</a>"
|
|
|
|
}
|
|
|
|
|
|
|
|
func linkPreviewImage(file: String) -> String {
|
|
|
|
"<meta property=\"og:image\" content=\"\(file)\" />"
|
|
|
|
}
|
|
|
|
|
|
|
|
func makePrevText(_ text: String) -> String {
|
|
|
|
"<span class=\"icon-back\"></span>\(text)"
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeNextText(_ text: String) -> String {
|
|
|
|
"\(text)<span class=\"icon-next\"></span>"
|
|
|
|
}
|
2022-08-29 13:35:25 +02:00
|
|
|
|
|
|
|
func svgImage(file: String) -> String {
|
|
|
|
"""
|
|
|
|
<span class="image">
|
|
|
|
<img src="\(file)"/>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
func svgImage(file: String, x: Int, y: Int, width: Int, height: Int) -> String {
|
|
|
|
"""
|
|
|
|
<span class="image">
|
|
|
|
<img src="\(file)#svgView(viewBox(\(x), \(y), \(width), \(height))" style="aspect-ratio:\(Float(width)/Float(height))"/>
|
|
|
|
</span>
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadButtons(_ buttons: [(file: String, text: String, downloadName: String?)]) -> String {
|
|
|
|
let content = buttons.map {
|
|
|
|
if let download = $0.downloadName {
|
|
|
|
return button(file: $0.file, text: $0.text, downloadName: download)
|
|
|
|
} else {
|
|
|
|
return button(file: $0.file, text: $0.text)
|
|
|
|
}
|
|
|
|
}.joined(separator: "\n")
|
|
|
|
return flexParagraph(content)
|
|
|
|
}
|
|
|
|
|
2022-08-30 11:29:53 +02:00
|
|
|
func externalButtons(_ buttons: [(url: String, text: String)]) -> String {
|
|
|
|
let content = buttons
|
|
|
|
.map { externalLink(url: $0.url, text: $0.text) }
|
|
|
|
.joined(separator: "\n")
|
|
|
|
return flexParagraph(content)
|
|
|
|
}
|
|
|
|
|
2022-08-29 13:35:25 +02:00
|
|
|
private func flexParagraph(_ content: String) -> String {
|
|
|
|
"""
|
|
|
|
<p style="display: flex">
|
|
|
|
\(content)
|
|
|
|
</p>
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
private func button(file: String, text: String) -> String {
|
|
|
|
"""
|
|
|
|
<a class="download-button" href="\(file)">
|
2022-08-30 11:29:53 +02:00
|
|
|
\(text)<span class="icon icon-download"></span>
|
2022-08-29 13:35:25 +02:00
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
private func button(file: String, text: String, downloadName: String) -> String {
|
|
|
|
"""
|
|
|
|
<a class="download-button" href="\(file)" download="\(downloadName)">
|
2022-08-30 11:29:53 +02:00
|
|
|
\(text)<span class="icon icon-download"></span>
|
2022-08-29 13:35:25 +02:00
|
|
|
</a>
|
2022-08-30 11:29:53 +02:00
|
|
|
"""
|
|
|
|
}
|
2022-08-29 13:35:25 +02:00
|
|
|
|
2022-08-30 11:29:53 +02:00
|
|
|
private func externalLink(url: String, text: String) -> String {
|
|
|
|
"""
|
|
|
|
<a class="download-button" href="\(url)">
|
|
|
|
\(text)<span class="icon icon-download icon-rotate"></span>
|
|
|
|
</a>
|
2022-08-29 13:35:25 +02:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
|
|
|
func scriptInclude(path: String) -> String {
|
|
|
|
"<script src=\"\(path)\"></script>"
|
|
|
|
}
|
|
|
|
|
|
|
|
func codeHighlightFooter() -> String {
|
|
|
|
"<script>hljs.highlightAll();</script>"
|
|
|
|
}
|
2022-08-28 11:14:11 +02:00
|
|
|
}
|