Rework storage structs, link preview
This commit is contained in:
@ -10,11 +10,11 @@ struct ImageSet: HtmlProducer {
|
||||
|
||||
let quality: CGFloat
|
||||
|
||||
let description: String
|
||||
let description: String?
|
||||
|
||||
let extraAttributes: String
|
||||
|
||||
init(image: FileResource, maxWidth: Int, maxHeight: Int, description: String, quality: CGFloat = 0.7, extraAttributes: String? = nil) {
|
||||
init(image: FileResource, maxWidth: Int, maxHeight: Int, description: String?, quality: CGFloat = 0.7, extraAttributes: String? = nil) {
|
||||
self.image = image
|
||||
self.maxWidth = maxWidth
|
||||
self.maxHeight = maxHeight
|
||||
@ -39,6 +39,13 @@ struct ImageSet: HtmlProducer {
|
||||
]
|
||||
}
|
||||
|
||||
private var imageAltText: String {
|
||||
guard let description else {
|
||||
return ""
|
||||
}
|
||||
return " alt='\(description.htmlEscaped())'"
|
||||
}
|
||||
|
||||
func populate(_ result: inout String) {
|
||||
let fileExtension = image.type.fileExtension.map { "." + $0 } ?? ""
|
||||
|
||||
@ -48,7 +55,7 @@ struct ImageSet: HtmlProducer {
|
||||
result += "<picture>"
|
||||
result += "<source type='image/avif' srcset='\(prefix1x).avif 1x, \(prefix2x).avif 2x'/>"
|
||||
result += "<source type='image/webp' srcset='\(prefix1x).webp 1x, \(prefix1x).webp 2x'/>"
|
||||
result += "<img srcset='\(prefix2x)\(fileExtension) 2x' src='\(prefix1x)\(fileExtension)' loading='lazy' alt='\(description.htmlEscaped())'\(extraAttributes)/>"
|
||||
result += "<img srcset='\(prefix2x)\(fileExtension) 2x' src='\(prefix1x)\(fileExtension)' loading='lazy'\(imageAltText)\(extraAttributes)/>"
|
||||
result += "</picture>"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user