Rework path storage, add start screen
This commit is contained in:
@ -81,16 +81,12 @@ extension Content {
|
||||
}
|
||||
// TODO: Fix bug where multiple generating operations can be started
|
||||
// due to dispatch of locking property on main queue
|
||||
DispatchQueue.main.async {
|
||||
self.isGeneratingWebsite = true
|
||||
}
|
||||
self.set(isGenerating: true)
|
||||
return true
|
||||
}
|
||||
|
||||
private func endGenerating() {
|
||||
DispatchQueue.main.async {
|
||||
self.isGeneratingWebsite = false
|
||||
}
|
||||
set(isGenerating: false)
|
||||
}
|
||||
|
||||
private func generateInternal(_ page: Page, in language: ContentLanguage) -> Bool {
|
||||
|
@ -41,12 +41,13 @@ extension Content {
|
||||
}
|
||||
|
||||
func loadFromDisk() throws {
|
||||
guard storageIsInitialized else {
|
||||
guard storage.hasContentFolders else {
|
||||
print("Storage not initialized, not loading content")
|
||||
return
|
||||
throw StorageAccessError.noBookmarkData
|
||||
}
|
||||
|
||||
let settings = try storage.loadSettings()
|
||||
let settings = try storage.loadSettings() // Uses defaults if missing
|
||||
print("Loaded settings")
|
||||
let imageDescriptions = try storage.loadFileDescriptions().reduce(into: [:]) { descriptions, description in
|
||||
descriptions[description.fileId] = description
|
||||
}
|
||||
@ -58,6 +59,16 @@ extension Content {
|
||||
let externalFiles = try storage.loadExternalFileList()
|
||||
let tagOverviewData = try storage.loadTagOverview()
|
||||
|
||||
if tagData.isEmpty { print("No tags loaded") }
|
||||
if pagesData.isEmpty { print("No pages loaded") }
|
||||
if postsData.isEmpty { print("No posts loaded") }
|
||||
if fileList.isEmpty { print("No files loaded") }
|
||||
if externalFiles.isEmpty { print("No external files loaded") }
|
||||
if tagOverviewData == nil { print("No tag overview loaded") }
|
||||
|
||||
print("Loaded data from disk, processing...")
|
||||
// All data loaded from storage, start constructing the data model
|
||||
|
||||
var files: [String : FileResource] = fileList.reduce(into: [:]) { files, fileId in
|
||||
let descriptions = imageDescriptions[fileId]
|
||||
files[fileId] = FileResource(
|
||||
@ -122,6 +133,7 @@ extension Content {
|
||||
self.posts = posts.sorted(ascending: false) { $0.startDate }
|
||||
self.tagOverview = tagOverview
|
||||
self.settings = makeSettings(settings, tags: tags, pages: pages, files: files)
|
||||
print("Content loaded")
|
||||
}
|
||||
|
||||
private func makeSettings(_ settings: SettingsFile, tags: [String : Tag], pages: [String : Page], files: [String : FileResource]) -> Settings {
|
||||
|
@ -3,7 +3,7 @@ import Foundation
|
||||
extension Content {
|
||||
|
||||
func saveToDisk() throws {
|
||||
guard storageIsInitialized else {
|
||||
guard storage.hasContentFolders else {
|
||||
print("Storage not initialized, not saving content")
|
||||
return
|
||||
}
|
||||
|
@ -4,10 +4,8 @@ import Combine
|
||||
|
||||
final class Content: ObservableObject {
|
||||
|
||||
let storage = Storage()
|
||||
|
||||
@Published
|
||||
var storageIsInitialized = false
|
||||
@ObservedObject
|
||||
var storage = Storage()
|
||||
|
||||
@Published
|
||||
var settings: Settings
|
||||
@ -28,10 +26,10 @@ final class Content: ObservableObject {
|
||||
var tagOverview: TagOverviewPage?
|
||||
|
||||
@Published
|
||||
var results: [ItemId : PageGenerationResults] = [:]
|
||||
private(set) var results: [ItemId : PageGenerationResults] = [:]
|
||||
|
||||
@Published
|
||||
var isGeneratingWebsite = false
|
||||
private(set) var isGeneratingWebsite = false
|
||||
|
||||
init(settings: Settings,
|
||||
posts: [Post],
|
||||
@ -45,8 +43,6 @@ final class Content: ObservableObject {
|
||||
self.tags = tags
|
||||
self.files = files
|
||||
self.tagOverview = tagOverview
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -56,28 +52,25 @@ final class Content: ObservableObject {
|
||||
self.tags = []
|
||||
self.files = []
|
||||
self.tagOverview = nil
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
||||
private func initialize() {
|
||||
guard storage.check(contentPath: settings.paths.contentDirectoryPath) == .nominal else {
|
||||
storageIsInitialized = false
|
||||
return
|
||||
}
|
||||
|
||||
storage.check(outputPath: settings.paths.outputDirectoryPath)
|
||||
|
||||
do {
|
||||
try storage.createFolderStructure()
|
||||
storageIsInitialized = true
|
||||
} catch {
|
||||
print("Failed to initialize storage: \(error)")
|
||||
storageIsInitialized = false
|
||||
}
|
||||
}
|
||||
|
||||
var images: [FileResource] {
|
||||
files.filter { $0.type.isImage }
|
||||
}
|
||||
|
||||
func set(isGenerating: Bool) {
|
||||
DispatchQueue.main.async {
|
||||
self.isGeneratingWebsite = isGenerating
|
||||
}
|
||||
}
|
||||
|
||||
func add(_ file: FileResource) {
|
||||
// TODO: Insert at correct index?
|
||||
files.insert(file, at: 0)
|
||||
}
|
||||
|
||||
func add(_ page: Page) {
|
||||
// TODO: Insert at correct index?
|
||||
pages.insert(page, at: 0)
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,6 @@ import Foundation
|
||||
|
||||
final class PathSettings: ObservableObject {
|
||||
|
||||
@Published
|
||||
var contentDirectoryPath: String
|
||||
|
||||
@Published
|
||||
var outputDirectoryPath: String
|
||||
|
||||
@Published
|
||||
var assetsOutputFolderPath: String
|
||||
|
||||
@ -27,9 +21,7 @@ final class PathSettings: ObservableObject {
|
||||
var tagsOutputFolderPath: String
|
||||
|
||||
init(file: PathSettingsFile) {
|
||||
self.contentDirectoryPath = file.contentDirectoryPath
|
||||
self.assetsOutputFolderPath = file.assetsOutputFolderPath
|
||||
self.outputDirectoryPath = file.outputDirectoryPath
|
||||
self.pagesOutputFolderPath = file.pagesOutputFolderPath
|
||||
self.imagesOutputFolderPath = file.imagesOutputFolderPath
|
||||
self.filesOutputFolderPath = file.filesOutputFolderPath
|
||||
@ -38,9 +30,7 @@ final class PathSettings: ObservableObject {
|
||||
}
|
||||
|
||||
var file: PathSettingsFile {
|
||||
.init(contentDirectoryPath: contentDirectoryPath,
|
||||
outputDirectoryPath: outputDirectoryPath,
|
||||
assetsOutputFolderPath: assetsOutputFolderPath,
|
||||
.init(assetsOutputFolderPath: assetsOutputFolderPath,
|
||||
pagesOutputFolderPath: pagesOutputFolderPath,
|
||||
imagesOutputFolderPath: imagesOutputFolderPath,
|
||||
filesOutputFolderPath: filesOutputFolderPath,
|
||||
|
@ -36,8 +36,4 @@ final class Settings: ObservableObject {
|
||||
case .german: return german
|
||||
}
|
||||
}
|
||||
|
||||
var outputDirectory: URL {
|
||||
URL(fileURLWithPath: paths.outputDirectoryPath)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user