151 lines
5.2 KiB
Swift
151 lines
5.2 KiB
Swift
import SwiftUI
|
|
|
|
struct GenerationContentView: View {
|
|
|
|
@Environment(\.language)
|
|
private var language
|
|
|
|
@EnvironmentObject
|
|
private var content: Content
|
|
|
|
@Binding
|
|
private var selectedSection: SettingsSection
|
|
|
|
init(selected: Binding<SettingsSection>) {
|
|
self._selectedSection = selected
|
|
}
|
|
|
|
var body: some View {
|
|
switch selectedSection {
|
|
case .folders, .navigationBar, .postFeed, .tagOverview:
|
|
generationView
|
|
case .pages:
|
|
PageSettingsContentView()
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var generationView: some View {
|
|
VStack(alignment: .leading) {
|
|
Text("Website Generation")
|
|
.font(.largeTitle)
|
|
.bold()
|
|
Text("Regenerate the website and monitor the output")
|
|
.foregroundStyle(.secondary)
|
|
.padding(.bottom, 30)
|
|
|
|
HStack {
|
|
Button {
|
|
if content.isGeneratingWebsite {
|
|
content.endCurrentGeneration()
|
|
} else {
|
|
generateFullWebsite()
|
|
}
|
|
} label: {
|
|
Text(content.isGeneratingWebsite ? "Cancel" : "Generate")
|
|
}
|
|
if content.isGeneratingWebsite {
|
|
ProgressView()
|
|
.progressViewStyle(.circular)
|
|
.frame(height: 25)
|
|
}
|
|
Spacer()
|
|
}
|
|
Text(content.generationStatus)
|
|
.padding(.vertical, 5)
|
|
HStack(spacing: 8) {
|
|
Text("\(content.results.imagesToGenerate.count) images")
|
|
Text("\(content.results.externalLinks.count) external links")
|
|
Text("\(content.results.resultCount) items processed")
|
|
Text("\(content.results.requiredFiles.count) files")
|
|
}
|
|
List {
|
|
Section("Empty pages") {
|
|
ForEach(content.results.emptyPages.sorted()) { id in
|
|
Text("\(id.pageId) (\(id.language))")
|
|
}
|
|
}
|
|
Section("Inaccessible files") {
|
|
ForEach(content.results.inaccessibleFiles.sorted()) { file in
|
|
Text(file.id)
|
|
}
|
|
}
|
|
Section("Unparsable files") {
|
|
ForEach(content.results.unparsableFiles.sorted()) { file in
|
|
Text(file.id)
|
|
}
|
|
}
|
|
Section("Missing files") {
|
|
ForEach(content.results.missingFiles.sorted(), id: \.self) { file in
|
|
Text(file)
|
|
}
|
|
}
|
|
Section("Missing tags") {
|
|
ForEach(content.results.missingTags.sorted(), id: \.self) { tag in
|
|
Text(tag)
|
|
}
|
|
}
|
|
Section("Missing pages") {
|
|
ForEach(content.results.missingPages.sorted(), id: \.self) { page in
|
|
Text(page)
|
|
}
|
|
}
|
|
Section("Invalid commands") {
|
|
ForEach(content.results.invalidCommands.sorted(), id: \.self) { markdown in
|
|
Text(markdown)
|
|
}
|
|
}
|
|
Section("Warnings") {
|
|
ForEach(content.results.warnings.sorted(), id: \.self) { warning in
|
|
Text(warning)
|
|
}
|
|
}
|
|
Section("Unsaved output files") {
|
|
ForEach(content.results.unsavedOutputFiles.sorted(), id: \.self) { file in
|
|
Text(file)
|
|
}
|
|
}
|
|
}
|
|
}.padding()
|
|
}
|
|
|
|
private func generateFullWebsite() {
|
|
DispatchQueue.main.async {
|
|
content.generateWebsiteInAllLanguages()
|
|
}
|
|
#warning("Update feed generation")
|
|
/*
|
|
guard let url = content.storage.outputPath else {
|
|
print("Invalid output path")
|
|
return
|
|
}
|
|
|
|
guard FileManager.default.fileExists(atPath: url.path) else {
|
|
print("Missing output folder")
|
|
return
|
|
}
|
|
isGeneratingWebsite = true
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
let generator = LocalizedWebsiteGenerator(
|
|
content: content,
|
|
language: language)
|
|
_ = generator.generateWebsite { text in
|
|
DispatchQueue.main.async {
|
|
self.generatorText = text
|
|
}
|
|
}
|
|
DispatchQueue.main.async {
|
|
isGeneratingWebsite = false
|
|
self.generatorText = "Generation complete"
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
GenerationContentView(selected: .constant(.folders))
|
|
.environmentObject(Content.mock)
|
|
.padding()
|
|
}
|