struct WebsiteImage { static func imagePath(prefix: String, width: Int, height: Int) -> String { "\(prefix)@\(width)x\(height)" } static func imagePath(prefix: String, extension fileExtension: String, width: Int, height: Int) -> String { "\(prefix)@\(width)x\(height).\(fileExtension)" } static func imagePath(source: String, width: Int, height: Int) -> String { let (prefix, ext) = source.fileNameAndExtension return imagePath(prefix: prefix, extension: ext ?? ".jpg", width: width, height: height) } private let prefix1x: String private let prefix2x: String private let altText: String private let ext: String init(image: FeedEntryData.Image) { self.init(rawImagePath: image.rawImagePath, width: image.width, height: image.height, altText: image.altText) } init(rawImagePath: String, width: Int, height: Int, altText: String) { let (prefix, ext) = rawImagePath.fileNameAndExtension self.prefix1x = WebsiteImage.imagePath(prefix: prefix, width: width, height: height) self.prefix2x = WebsiteImage.imagePath(prefix: prefix, width: 2*width, height: 2*height) self.altText = altText.htmlEscaped() self.ext = ext ?? "jpg" } var content: String { var result = "" result += "" result += "" result += "\(altText)" result += "" return result } }