import Foundation struct ImageGallery { let id: String let images: [FeedEntryData.Image] private var htmlSafeId: String { ImageGallery.htmlSafe(id) } init(id: String, images: [FeedEntryData.Image]) { self.id = id self.images = images } private func imageCode(_ image: FeedEntryData.Image) -> String { //return "\(image.altText.htmlEscaped())" var result = "" result += "" result += "" result += "\(image.altText.htmlEscaped())" result += "" return result } func addContent(to result: inout String) { guard !images.isEmpty else { return } result += "
" guard images.count > 1 else { result += imageCode(images[0]) result += "
" // Close swiper, swiper-wrapper return } for image in images { // TODO: Use different images based on device result += "
" result += imageCode(image) result += "
" result += "
" // Close swiper-slide } result += "" // Close swiper-wrapper result += "
" result += "
" result += "
" result += "" // Close swiper } private static func htmlSafe(_ id: String) -> String { id.replacingOccurrences(of: "-", with: "_") } static func swiperInit(id: String) -> String { let id = htmlSafe(id) return """ var swiper_\(id) = new Swiper("#\(id)", { loop: true, slidesPerView: 1, spaceBetween: 30, centeredSlides: true, keyboard: { enabled: true }, pagination: { el: "#\(id) .swiper-pagination", clickable: true }, navigation: { nextEl: "#\(id) .swiper-button-next", prevEl: "#\(id) .swiper-button-prev" } }); """ } } /* extension ImageGallery: HTML { var content: some HTML { div(.id(id), .class("swiper")) { div(.class("swiper-wrapper")) { for image in images { div(.class("swiper-slide")) { // TODO: Use different images based on device img(.src(image.mainImageUrl), .lazyLoad) div(.class("swiper-lazy-preloader"), .class("swiper-lazy-preloader-white")) { } } } } div(.class("swiper-button-next")) { } div(.class("swiper-button-prev")) { } div(.class("swiper-pagination")) { } } } } */