Colors, pages, post links

This commit is contained in:
Christoph Hagen
2024-11-20 13:53:44 +01:00
parent 943d8d962b
commit 8ae2a237cc
19 changed files with 466 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
import Foundation
import SwiftUI
import Combine
final class Content: ObservableObject {
@@ -19,7 +20,64 @@ final class Content: ObservableObject {
var files: [FileResources] = []
@AppStorage("contentPath")
var contentPath: String = ""
private var storedContentPath: String = ""
@Published
var contentPath: String = "" {
didSet {
storedContentPath = contentPath
}
}
let storage: Storage
private var cancellables = Set<AnyCancellable>()
init(posts: [Post] = [],
pages: [Page] = [],
tags: [Tag] = [],
images: [ImageResource] = [],
files: [FileResources] = [],
storedContentPath: String) {
self.posts = posts
self.pages = pages
self.tags = tags
self.images = images
self.files = files
self.storedContentPath = storedContentPath
self.contentPath = storedContentPath
self.storage = Storage(baseFolder: URL(filePath: storedContentPath))
do {
try storage.createFolderStructure()
} catch {
print(error)
return
}
observeContentPath()
}
init() {
self.storage = Storage(baseFolder: URL(filePath: ""))
contentPath = storedContentPath
do {
try storage.createFolderStructure()
} catch {
print(error)
return
}
try? storage.update(baseFolder: URL(filePath: contentPath), moveContent: false)
observeContentPath()
}
private func observeContentPath() {
$contentPath.sink { newValue in
let url = URL(filePath: newValue)
try? self.storage.update(baseFolder: url, moveContent: true)
}
.store(in: &cancellables)
}
func generateFeed(for language: ContentLanguage, bookmarkKey: String) {
let posts = posts.map { $0.feedEntry(for: language) }
@@ -60,13 +118,6 @@ final class Content: ObservableObject {
}
func importOldContent() {
let storage = Storage(baseFolder: URL(filePath: "/Users/ch/Downloads/Content"))
do {
try storage.createFolderStructure()
} catch {
print(error)
return
}
let importer = Importer()
do {