Generate first feed pages, images
This commit is contained in:
@ -15,10 +15,7 @@ struct SettingsView: View {
|
||||
var content: Content
|
||||
|
||||
@State
|
||||
private var isSelectingContentFolder = false
|
||||
|
||||
@State
|
||||
private var showFileImporter = false
|
||||
private var folderSelection: SecurityScopeBookmark = .contentPath
|
||||
|
||||
@State
|
||||
private var showTagPicker = false
|
||||
@ -70,6 +67,7 @@ struct SettingsView: View {
|
||||
Button(action: generateFeed) {
|
||||
Text("Generate")
|
||||
}
|
||||
.disabled(isGeneratingWebsite)
|
||||
if isGeneratingWebsite {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
@ -80,10 +78,6 @@ struct SettingsView: View {
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.fileImporter(
|
||||
isPresented: $showFileImporter,
|
||||
allowedContentTypes: [.folder],
|
||||
onCompletion: didSelectContentFolder)
|
||||
.sheet(isPresented: $showTagPicker) {
|
||||
TagSelectionView(
|
||||
presented: $showTagPicker,
|
||||
@ -95,43 +89,21 @@ struct SettingsView: View {
|
||||
// MARK: Folder selection
|
||||
|
||||
private func selectContentFolder() {
|
||||
isSelectingContentFolder = true
|
||||
//showFileImporter = true
|
||||
guard let url = savePanelUsingOpenPanel(key: Storage.contentPathBookmarkKey) else {
|
||||
folderSelection = .contentPath
|
||||
guard let url = savePanelUsingOpenPanel() else {
|
||||
return
|
||||
}
|
||||
self.contentPath = url.path()
|
||||
}
|
||||
|
||||
private func selectOutputFolder() {
|
||||
isSelectingContentFolder = false
|
||||
guard let url = savePanelUsingOpenPanel(key: Storage.outputPathBookmarkKey) else {
|
||||
folderSelection = .outputPath
|
||||
guard let url = savePanelUsingOpenPanel() else {
|
||||
return
|
||||
}
|
||||
self.outputPath = url.path()
|
||||
}
|
||||
|
||||
private func didSelectContentFolder(_ result: Result<URL, any Error>) {
|
||||
switch result {
|
||||
case .success(let url):
|
||||
didSelect(folder: url)
|
||||
case .failure(let error):
|
||||
print("Failed to select content folder: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func didSelect(folder: URL) {
|
||||
let path = folder.absoluteString
|
||||
.replacingOccurrences(of: "file://", with: "")
|
||||
if isSelectingContentFolder {
|
||||
self.contentPath = path
|
||||
saveSecurityScopedBookmark(folder, key: Storage.contentPathBookmarkKey)
|
||||
} else {
|
||||
self.outputPath = path
|
||||
saveSecurityScopedBookmark(folder, key: Storage.outputPathBookmarkKey)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Feed
|
||||
|
||||
private func generateFeed() {
|
||||
@ -150,7 +122,7 @@ struct SettingsView: View {
|
||||
let generator = WebsiteGenerator(
|
||||
content: content,
|
||||
configuration: configuration)
|
||||
generator.generateWebsite()
|
||||
_ = generator.generateWebsite()
|
||||
DispatchQueue.main.async {
|
||||
isGeneratingWebsite = false
|
||||
}
|
||||
@ -158,13 +130,18 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
private var configuration: WebsiteGeneratorConfiguration {
|
||||
switch language {
|
||||
case .english: return .english
|
||||
case .german: return .german
|
||||
}
|
||||
return .init(
|
||||
language: language,
|
||||
outputDirectory: URL(filePath: outputPath, directoryHint: .isDirectory),
|
||||
postsPerPage: 20,
|
||||
postFeedTitle: "Posts",
|
||||
postFeedDescription: "The most recent posts on christophhagen.de",
|
||||
postFeedUrlPrefix: "feed",
|
||||
navigationIconPath: "/assets/icons/ch.svg",
|
||||
mainContentMaximumWidth: 600)
|
||||
}
|
||||
|
||||
func savePanelUsingOpenPanel(key: String) -> URL? {
|
||||
func savePanelUsingOpenPanel() -> URL? {
|
||||
let panel = NSOpenPanel()
|
||||
// Sets up so user can only select a single directory
|
||||
panel.canChooseFiles = false
|
||||
@ -182,19 +159,9 @@ struct SettingsView: View {
|
||||
guard let url = panel.url else {
|
||||
return nil
|
||||
}
|
||||
saveSecurityScopedBookmark(url, key: key)
|
||||
content.storage.save(folderUrl: url, in: folderSelection)
|
||||
return url
|
||||
}
|
||||
|
||||
func saveSecurityScopedBookmark(_ url: URL, key: String) {
|
||||
do {
|
||||
let bookmarkData = try url.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil)
|
||||
UserDefaults.standard.set(bookmarkData, forKey: key)
|
||||
print("Security-scoped bookmark saved.")
|
||||
} catch {
|
||||
print("Failed to create security-scoped bookmark: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
Reference in New Issue
Block a user