71 lines
2.0 KiB
Swift
71 lines
2.0 KiB
Swift
|
|
struct PageHeader: HtmlProducer {
|
|
|
|
let language: ContentLanguage
|
|
|
|
let iconUrl: String
|
|
|
|
let languageButton: NavigationBar.Link
|
|
|
|
let links: [NavigationBar.Link]
|
|
|
|
let headers: [HeaderElement]
|
|
|
|
let icons: Set<PageIcon>
|
|
|
|
init(
|
|
language: ContentLanguage,
|
|
title: String?,
|
|
description: String?,
|
|
image: String?,
|
|
pageUrl: String,
|
|
iconUrl: String,
|
|
languageButton: NavigationBar.Link,
|
|
links: [NavigationBar.Link],
|
|
headers: Set<HeaderElement>,
|
|
icons: Set<PageIcon>) {
|
|
self.language = language
|
|
self.iconUrl = iconUrl
|
|
self.languageButton = languageButton
|
|
self.links = links
|
|
self.icons = icons
|
|
|
|
var headers = headers
|
|
if let title {
|
|
headers.insert(.title(title))
|
|
headers.insert(.ogTitle(title))
|
|
}
|
|
if let description {
|
|
headers.insert(.description(description))
|
|
headers.insert(.ogDescription(description))
|
|
}
|
|
if let image {
|
|
headers.insert(.ogImage(image))
|
|
}
|
|
headers.insert(.ogUrl(pageUrl))
|
|
self.headers = headers.sorted()
|
|
}
|
|
|
|
func populate(_ result: inout String) {
|
|
result += "<!DOCTYPE html><html lang=\"\(language.rawValue)\">"
|
|
result += PageHead(items: headers).content
|
|
result += "<body>"
|
|
result += NavigationBar(links: links, languageButton: languageButton, iconUrl: iconUrl).content
|
|
result += symbols // Add the svg images required by the page as hidden elements
|
|
result += "<main>"
|
|
result += "<div class='navbar-spacer'></div>"
|
|
}
|
|
|
|
private var symbols: String {
|
|
guard !icons.isEmpty else {
|
|
return ""
|
|
}
|
|
var result = "<div style='display:none'>"
|
|
for icon in icons.sorted(using: { $0.id} ) {
|
|
result += icon.icon.svgString
|
|
}
|
|
result += "</div>"
|
|
return result
|
|
}
|
|
}
|