Allow videos in posts, simplify post image view

This commit is contained in:
Christoph Hagen
2025-01-17 23:24:56 +01:00
parent 60716fca20
commit bc3f21e7e4
10 changed files with 175 additions and 172 deletions

View File

@ -0,0 +1,14 @@
struct PostVideo: HtmlProducer {
let videos: [FileResource]
func populate(_ result: inout String) {
result += "<video autoplay loop muted>"
result += "Video not supported."
for video in videos {
result += "<source src='\(video.absoluteUrl)' type='\(video.type.htmlType!)'>"
}
result += "</video>"
}
}

View File

@ -14,7 +14,14 @@ struct FeedEntry {
var content: String {
var result = "<article><div class='card\(cardLinkClassText)'>"
ImageGallery(id: data.entryId, images: data.images).populate(&result)
switch data.media {
case .images(let images):
ImageGallery(id: data.entryId, images: images).populate(&result)
case .video(let videos):
PostVideo(videos: videos).populate(&result)
case .none:
break
}
if let url = data.link?.url {
result += "<div class='card-content' onclick=\"window.location.href='\(url)'\">"

View File

@ -13,16 +13,16 @@ struct FeedEntryData {
let text: [String]
let images: [ImageSet]
let media: Media?
init(entryId: String, title: String?, textAboveTitle: String, link: Link?, tags: [Tag], text: [String], images: [ImageSet]) {
init(entryId: String, title: String?, textAboveTitle: String, link: Link?, tags: [Tag], text: [String], media: Media?) {
self.entryId = entryId
self.title = title
self.textAboveTitle = textAboveTitle
self.link = link
self.tags = tags
self.text = text
self.images = images
self.media = media
}
struct Link {
@ -40,4 +40,16 @@ struct FeedEntryData {
let url: String
}
enum Media {
case images([ImageSet])
case video([FileResource])
}
var requiresSwiper: Bool {
if case .images(let images) = media, images.count > 1 {
return true
}
return false
}
}