70 lines
2.1 KiB
Swift
70 lines
2.1 KiB
Swift
import Foundation
|
|
|
|
struct ContentPage: HtmlProducer {
|
|
|
|
private let linkTitle: String
|
|
|
|
private let description: String
|
|
|
|
private let language: ContentLanguage
|
|
|
|
private let dateString: String
|
|
|
|
private let title: String
|
|
|
|
private let tags: [FeedEntryData.Tag]
|
|
|
|
private let navigationBarLinks: [NavigationBar.Link]
|
|
|
|
private let pageContent: String
|
|
|
|
private let headers: [HeaderElement]
|
|
|
|
private let footers: String
|
|
|
|
private let icons: Set<PageIcon>
|
|
|
|
init(language: ContentLanguage, dateString: String, title: String, tags: [FeedEntryData.Tag], linkTitle: String, description: String, navigationBarLinks: [NavigationBar.Link], pageContent: String, headers: Set<HeaderElement>, footers: [String], icons: Set<PageIcon>) {
|
|
self.language = language
|
|
self.dateString = dateString
|
|
self.title = title
|
|
self.tags = tags
|
|
self.linkTitle = linkTitle
|
|
self.description = description
|
|
self.navigationBarLinks = navigationBarLinks
|
|
self.pageContent = pageContent
|
|
self.headers = headers.union([.title(title), .description(description)]).sorted()
|
|
self.footers = footers.joined()
|
|
self.icons = icons
|
|
}
|
|
|
|
func populate(_ result: inout String) {
|
|
// TODO: Add headers and footers from page content
|
|
result += "<!DOCTYPE html><html lang=\"\(language.rawValue)\">"
|
|
result += PageHead(items: headers).content
|
|
result += "<body>"
|
|
result += NavigationBar(links: navigationBarLinks).content
|
|
|
|
result += "<main><article>"
|
|
result += "<div style=\"height: 70px;\"></div>"
|
|
result += "<h3>\(dateString)</h3>"
|
|
result += "<h1>\(title)</h1>"
|
|
result += TagList(tags: tags).content
|
|
result += symbols
|
|
result += pageContent
|
|
result += "</article></main>"
|
|
|
|
result += footers
|
|
result += "</body></html>" // Close content
|
|
}
|
|
|
|
private var symbols: String {
|
|
var result = "<div style='display:none'>"
|
|
for icon in icons {
|
|
result += icon.icon.content
|
|
}
|
|
result += "</div>"
|
|
return result
|
|
}
|
|
}
|