Add navigation settings, fix page generation
This commit is contained in:
60
CHDataManagement/Page Elements/PageHeader.swift
Normal file
60
CHDataManagement/Page Elements/PageHeader.swift
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
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?,
|
||||
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
|
||||
headers.insert(.title(title))
|
||||
if let description {
|
||||
headers.insert(.description(description))
|
||||
}
|
||||
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 {
|
||||
result += icon.icon.content
|
||||
}
|
||||
result += "</div>"
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user