Improve asset handling

This commit is contained in:
Christoph Hagen
2024-12-16 15:36:58 +01:00
parent 31d1ecb8bd
commit b22b76fd32
21 changed files with 264 additions and 85 deletions

View File

@ -9,6 +9,15 @@ struct FilePropertyView: View {
@Binding
var selectedFile: FileResource?
let allowedType: FileFilterType?
init(title: LocalizedStringKey, footer: LocalizedStringKey, selectedFile: Binding<FileResource?>, allowedType: FileFilterType? = nil) {
self.title = title
self.footer = footer
self._selectedFile = selectedFile
self.allowedType = allowedType
}
@State
private var showFileSelectionSheet = false
@ -23,7 +32,7 @@ struct FilePropertyView: View {
}
}
.sheet(isPresented: $showFileSelectionSheet) {
FileSelectionView(selectedFile: $selectedFile)
FileSelectionView(selectedFile: $selectedFile, allowedType: allowedType)
}
}
}

View File

@ -12,9 +12,6 @@ struct PageDetailView: View {
@ObservedObject
private var page: Page
@State
private var isGeneratingWebsite = false
@State
private var didGenerateWebsite: Bool?
@ -28,11 +25,11 @@ struct PageDetailView: View {
DetailTitle(
title: "Page",
text: "A page contains longer content")
HStack {
HStack(alignment: .firstTextBaseline) {
Button(action: generate) {
Text("Generate")
}
.disabled(isGeneratingWebsite)
.disabled(content.isGeneratingWebsite)
if let didGenerateWebsite {
if didGenerateWebsite {
Image(systemSymbol: .checkmarkCircleFill)
@ -93,20 +90,9 @@ struct PageDetailView: View {
print("Missing output folder")
return
}
isGeneratingWebsite = true
DispatchQueue.global(qos: .userInitiated).async {
var success = true
for language in ContentLanguage.allCases {
let generator = LocalizedWebsiteGenerator(
content: content,
language: language)
if !generator.generate(page: page) {
print("Generation failed")
success = false
}
}
let success = content.generatePage(page)
DispatchQueue.main.async {
isGeneratingWebsite = false
didGenerateWebsite = success
}
}

View File

@ -42,6 +42,7 @@ struct NavigationBarSettingsView: View {
Text("Select the tags to show in the navigation bar. The number should be even.")
.foregroundStyle(.secondary)
}
.padding()
}
.sheet(isPresented: $showItemPicker) {
ItemSelectionView(

View File

@ -33,28 +33,34 @@ struct PageSettingsDetailView: View {
FilePropertyView(
title: "Default CSS File",
footer: "The CSS file containing the styling of all pages",
selectedFile: $content.settings.pages.defaultCssFile)
selectedFile: $content.settings.pages.defaultCssFile,
allowedType: .text)
FilePropertyView(
title: "Code Highlighting File",
footer: "The JavaScript file to provide syntax highlighting of code blocks",
selectedFile: $content.settings.pages.codeHighlightingJsFile)
selectedFile: $content.settings.pages.codeHighlightingJsFile,
allowedType: .text)
FilePropertyView(
title: "Audio Player CSS File",
footer: "The CSS file to provide the style for the audio player",
selectedFile: $content.settings.pages.audioPlayerCssFile)
selectedFile: $content.settings.pages.audioPlayerCssFile,
allowedType: .text)
FilePropertyView(
title: "Audio Player JavaScript File",
footer: "The CSS file to provide the functionality for the audio player",
selectedFile: $content.settings.pages.audioPlayerJsFile)
selectedFile: $content.settings.pages.audioPlayerJsFile,
allowedType: .text)
FilePropertyView(
title: "3D Model Viewer File",
footer: "The JavaScript file to provide the functionality for the 3D model viewer",
selectedFile: $content.settings.pages.modelViewerJsFile)
selectedFile: $content.settings.pages.modelViewerJsFile,
allowedType: .text)
}
.padding()
}
}
}

View File

@ -42,6 +42,7 @@ struct PostFeedSettingsView: View {
LocalizedPostFeedSettingsView(
settings: content.settings.localized(in: language))
}
.padding()
}
}
}

View File

@ -70,5 +70,6 @@ private struct TagOverviewDetails: View {
text: $page.linkPreviewDescription,
footer: "The description to show in previews of the page")
}
.padding()
}
}