Consolidate HTML element functions
This commit is contained in:
@ -9,4 +9,29 @@ struct HTMLElementsGenerator {
|
||||
func make(title: String, suffix: String) -> String {
|
||||
"\(title)<span class=\"suffix\">\(suffix)</span>"
|
||||
}
|
||||
|
||||
// - 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>"
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ struct PageGenerator {
|
||||
}
|
||||
let pageContent = makeContent(page: page, language: language, path: inputContentPath)
|
||||
content[.content] = pageContent ?? factory.placeholder
|
||||
content[.previousPageLinkText] = previousPage.unwrapped { factory.makePrevText($0.text) }
|
||||
content[.previousPageLinkText] = previousPage.unwrapped { factory.factory.html.makePrevText($0.text) }
|
||||
content[.previousPageUrl] = previousPage?.link
|
||||
content[.nextPageLinkText] = nextPage.unwrapped { factory.makeNextText($0.text) }
|
||||
content[.nextPageLinkText] = nextPage.unwrapped { factory.factory.html.makeNextText($0.text) }
|
||||
content[.nextPageUrl] = nextPage?.link
|
||||
content[.footer] = page.customFooterContent()
|
||||
|
||||
|
@ -4,10 +4,10 @@ struct PageHeadGenerator {
|
||||
|
||||
static let linkPreviewDesiredImageWidth = 1600
|
||||
|
||||
let template: PageHeadTemplate
|
||||
let factory: TemplateFactory
|
||||
|
||||
init(factory: TemplateFactory) {
|
||||
self.template = factory.pageHead
|
||||
self.factory = factory
|
||||
}
|
||||
|
||||
func generate(page: Element, language: String) -> String {
|
||||
@ -28,10 +28,10 @@ struct PageHeadGenerator {
|
||||
source: sourceImagePath,
|
||||
destination: destinationImagePath,
|
||||
width: PageHeadGenerator.linkPreviewDesiredImageWidth)
|
||||
content[.image] = "<meta property=\"og:image\" content=\"\(linkPreviewImageName)\" />"
|
||||
content[.image] = factory.html.linkPreviewImage(file: linkPreviewImageName)
|
||||
}
|
||||
content[.customPageContent] = page.customHeadContent()
|
||||
|
||||
return template.generate(content)
|
||||
return factory.pageHead.generate(content)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user