2024-12-06 21:59:36 +01:00

35 lines
787 B
Swift

struct DownloadButtons {
struct Item {
let filePath: String
let text: String
let downloadFileName: String?
}
let items: [Item]
init(items: [Item]) {
self.items = items
}
var content: String {
var result = "<p style='display: flex'>"
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='download-button' href='\(item.filePath)'\(downloadText)>"
result += "\(item.text)<span class='icon icon-download'></span>"
result += "</a>"
}
}