Reorganize saving, generate feed
This commit is contained in:
52
CHDataManagement/Page Elements/NavigationBar.swift
Normal file
52
CHDataManagement/Page Elements/NavigationBar.swift
Normal file
@ -0,0 +1,52 @@
|
||||
import Foundation
|
||||
|
||||
struct NavigationBarLink {
|
||||
|
||||
let text: String
|
||||
|
||||
let url: String
|
||||
}
|
||||
|
||||
|
||||
struct NavigationBarData {
|
||||
|
||||
let navigationIconPath: String
|
||||
|
||||
let iconDescription: String
|
||||
|
||||
let navigationItems: [NavigationBarLink]
|
||||
}
|
||||
|
||||
|
||||
struct NavigationBar {
|
||||
|
||||
let data: NavigationBarData
|
||||
|
||||
init(data: NavigationBarData) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
private var items: [NavigationBarLink] {
|
||||
data.navigationItems
|
||||
}
|
||||
|
||||
var content: String {
|
||||
var result = "<nav class=\"navbar\"><div class=\"navbar-fade\"></div><div class=\"nav-center\">"
|
||||
let middleIndex = items.count / 2
|
||||
let leftNavigationItems = items[..<middleIndex]
|
||||
let rightNavigationItems = items[middleIndex...]
|
||||
|
||||
for item in leftNavigationItems {
|
||||
result += "<a class=\"nav-animate\" href=\"\(item.url)\">\(item.text)</a>"
|
||||
}
|
||||
|
||||
result += "<a id=\"nav-image\" href=\"/\">"
|
||||
result += "<img class=\"navbar-icon\" src=\"\(data.navigationIconPath)\" alt=\"\(data.iconDescription)\">"
|
||||
|
||||
for item in rightNavigationItems {
|
||||
result += "<a class=\"nav-animate\" href=\"\(item.url)\">\(item.text)</a>"
|
||||
}
|
||||
result += "</div></nav>" // Close nav-center, navbar
|
||||
return result
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ struct PageHead {
|
||||
|
||||
let description: String
|
||||
|
||||
let additionalHeaders: String
|
||||
|
||||
var content: String {
|
||||
"""
|
||||
<head>
|
||||
@ -14,7 +16,7 @@ struct PageHead {
|
||||
<title>\(title)</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" />
|
||||
<meta name="description" content="\(description)">
|
||||
<link rel="stylesheet" href="/assets/swiper/swiper.css" />
|
||||
\(additionalHeaders)
|
||||
<link rel="stylesheet" href="/assets/css/style.css" />
|
||||
</head>
|
||||
"""
|
||||
|
88
CHDataManagement/Page Elements/PostFeedPageNavigation.swift
Normal file
88
CHDataManagement/Page Elements/PostFeedPageNavigation.swift
Normal file
@ -0,0 +1,88 @@
|
||||
import Foundation
|
||||
|
||||
struct PostFeedPageNavigation {
|
||||
|
||||
let language: ContentLanguage
|
||||
|
||||
let currentPage: Int
|
||||
|
||||
let numberOfPages: Int
|
||||
|
||||
init(currentPage: Int, numberOfPages: Int, language: ContentLanguage) {
|
||||
self.currentPage = currentPage
|
||||
self.numberOfPages = numberOfPages
|
||||
self.language = language
|
||||
}
|
||||
|
||||
private func pageLink(_ page: Int) -> String {
|
||||
guard page > 1 else { return "href='/feed'" }
|
||||
return "href='/feed-\(page)'"
|
||||
}
|
||||
|
||||
private func previousText() -> String {
|
||||
switch language {
|
||||
case .english:
|
||||
return "Previous"
|
||||
case .german:
|
||||
return "Zurück"
|
||||
}
|
||||
}
|
||||
|
||||
private func addPreviousButton(to result: inout String) {
|
||||
if currentPage == 1 {
|
||||
// Disable the previous button if we are on the first page
|
||||
result += "<a class='tag prev disabled' href='' aria-label='Previous'>"
|
||||
} else {
|
||||
let link = pageLink(currentPage - 1)
|
||||
result += "<a class='tag prev' \(link) aria-label='Previous'>"
|
||||
}
|
||||
result += "<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='currentColor'>"
|
||||
result += "<path stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M15 19l-7-7 7-7' />"
|
||||
result += "</svg></a>"
|
||||
}
|
||||
|
||||
private func addNextButton(to result: inout String) {
|
||||
if currentPage == numberOfPages {
|
||||
// Disable the previous button if we are on the first page
|
||||
result += "<a class='tag next disabled' href='' aria-label='Next'>"
|
||||
} else {
|
||||
let link = pageLink(currentPage + 1)
|
||||
result += "<a class='tag next' \(link) aria-label='Next'>"
|
||||
}
|
||||
result += "<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='currentColor'>"
|
||||
result += "<path stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M9 5l7 7-7 7' />"
|
||||
result += "</svg></a>"
|
||||
}
|
||||
|
||||
private func addLink(page: Int, to result: inout String) {
|
||||
result += "<a class='tag' \(pageLink(page))>\(page)</a>"
|
||||
}
|
||||
|
||||
var content: String {
|
||||
var result = "<div class='pagination'>"
|
||||
addPreviousButton(to: &result)
|
||||
// Add a maximum of two buttons before the current page
|
||||
if currentPage > 2 {
|
||||
addLink(page: currentPage - 2, to: &result)
|
||||
}
|
||||
if currentPage > 1 {
|
||||
addLink(page: currentPage - 1, to: &result)
|
||||
}
|
||||
|
||||
// Add the current page
|
||||
result += "<span class='tag current'>\(currentPage)</span>"
|
||||
|
||||
// Add a maximum of two buttons after the current page
|
||||
if currentPage < numberOfPages {
|
||||
addLink(page: currentPage + 1, to: &result)
|
||||
}
|
||||
if currentPage + 1 < numberOfPages {
|
||||
addLink(page: currentPage + 2, to: &result)
|
||||
}
|
||||
|
||||
addNextButton(to: &result)
|
||||
|
||||
result += "</div>" // Close pagination
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user