44 lines
1.0 KiB
Swift
44 lines
1.0 KiB
Swift
|
|
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>"
|
|
}
|
|
}
|