External files, improve page generation
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
|
||||
struct ContentButtons {
|
||||
|
||||
struct Item {
|
||||
|
||||
let icon: PageIcon
|
||||
|
||||
let filePath: String
|
||||
|
||||
let text: String
|
||||
|
||||
let downloadFileName: String?
|
||||
|
||||
init(icon: PageIcon, filePath: String, text: String, downloadFileName: String? = nil) {
|
||||
self.icon = icon
|
||||
self.filePath = filePath
|
||||
self.text = text
|
||||
self.downloadFileName = downloadFileName
|
||||
}
|
||||
}
|
||||
|
||||
let items: [Item]
|
||||
|
||||
init(items: [Item]) {
|
||||
self.items = items
|
||||
}
|
||||
|
||||
var content: String {
|
||||
var result = "<p class='tags tag-buttons'>"
|
||||
for item in items {
|
||||
addButton(of: item, to: &result)
|
||||
}
|
||||
result += "</p>"
|
||||
return result
|
||||
}
|
||||
|
||||
private func addButton(of item: Item, to result: inout String) {
|
||||
let downloadText = item.downloadFileName.map { " download='\($0)'" } ?? ""
|
||||
result += "<a class='tag' href='\(item.filePath)'\(downloadText)>"
|
||||
result += "<svg><use href='#\(item.icon.name)'></use></svg>\(item.text)"
|
||||
result += "</a>"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user