80 lines
2.6 KiB
Swift
80 lines
2.6 KiB
Swift
import Foundation
|
|
|
|
struct FeedNavigationLink {
|
|
|
|
let text: LocalizedText
|
|
|
|
let url: LocalizedText
|
|
}
|
|
|
|
struct Feed {
|
|
|
|
private let navigationIconPath = "/assets/icons/ch.svg"
|
|
|
|
let language: ContentLanguage
|
|
|
|
let title: LocalizedText
|
|
|
|
let description: LocalizedText
|
|
|
|
let iconDescription: LocalizedText
|
|
|
|
let navigationItems: [FeedNavigationLink]
|
|
|
|
let posts: [FeedEntryData]
|
|
|
|
var content: String {
|
|
#warning("TODO: Split feed into multiple pages")
|
|
var result = ""
|
|
result += "<!DOCTYPE html><html lang=\"\(language.rawValue)\">"
|
|
let head = PageHead(
|
|
title: title.getText(for: language),
|
|
description: description.getText(for: language))
|
|
result += head.content
|
|
result += "<body>"
|
|
addNavbar(to: &result)
|
|
result += "<div class=\"content\"><div style=\"height: 70px;\"></div>"
|
|
for post in posts {
|
|
FeedEntry(data: post)
|
|
.addContent(to: &result)
|
|
}
|
|
|
|
addSwiperInits(to: &result)
|
|
result += "</div></body></html>" // Close content
|
|
return result
|
|
}
|
|
|
|
#warning("TODO: Set correct navigation links and texts")
|
|
private func addNavbar(to result: inout String) {
|
|
result += "<nav class=\"navbar\"><div class=\"navbar-fade\"></div><div class=\"nav-center\">"
|
|
let middleIndex = navigationItems.count / 2
|
|
let leftNavigationItems = navigationItems[..<middleIndex]
|
|
let rightNavigationItems = navigationItems[middleIndex...]
|
|
|
|
for item in leftNavigationItems {
|
|
result += "<a class=\"nav-animate\" href=\"\(item.url.getText(for: language))\">\(item.text.getText(for: language))</a>"
|
|
}
|
|
|
|
result += "<a id=\"nav-image\" href=\"/\">"
|
|
result += "<img class=\"navbar-icon\" src=\"\(navigationIconPath)\" alt=\"\(iconDescription.getText(for: language))\">"
|
|
|
|
for item in rightNavigationItems {
|
|
result += "<a class=\"nav-animate\" href=\"\(item.url.getText(for: language))\">\(item.text.getText(for: language))</a>"
|
|
}
|
|
result += "</div></nav>" // Close nav-center, navbar
|
|
}
|
|
|
|
private func addSwiperInits(to result: inout String) {
|
|
if posts.contains(where: { $0.images.count > 1 }) {
|
|
result += "<script src=\"/assets/swiper/swiper.min.js\"></script><script>"
|
|
for post in posts {
|
|
guard post.images.count > 1 else {
|
|
continue
|
|
}
|
|
result += ImageGallery.swiperInit(id: post.entryId)
|
|
}
|
|
result += "</script>"
|
|
}
|
|
}
|
|
}
|