Generate images in correct order, show failures

This commit is contained in:
Christoph Hagen 2025-02-16 16:00:28 +01:00
parent 6b6db702f1
commit ece39cb95e
3 changed files with 39 additions and 11 deletions

View File

@ -19,7 +19,7 @@ final class ImageGenerator {
settings.paths.imagesOutputFolderPath
}
private func needsToGenerate(_ version: ImageVersion) -> Bool {
func needsToGenerate(_ version: ImageVersion) -> Bool {
if version.wasPreviouslyGenerated {
return !exists(version)
}
@ -44,10 +44,6 @@ final class ImageGenerator {
// MARK: Image operations
func generate(version: ImageVersion) -> Bool {
guard needsToGenerate(version) else {
return true
}
if version.type == .avif {
if version.image.type == .gif {
// Skip GIFs, since they can't be converted by avifenc

View File

@ -72,19 +72,48 @@ extension Content {
private func generateRequiredImages() {
let images = results.imagesToGenerate.sorted()
let count = images.count
var completed = 0
func didFinishOneImage() {
completed += 1
status("Generating required images: \(completed) / \(count)")
}
// Finish existing images
var newImagesToGenerate: [ImageVersion] = []
var avifImagesToGenerate: [ImageVersion] = []
for image in images {
guard shouldGenerateWebsite else { return }
defer {
completed += 1
status("Generating required images: \(completed) / \(count)")
}
if imageGenerator.generate(version: image) {
guard imageGenerator.needsToGenerate(image) else {
results.created(outputFile: image.outputPath)
didFinishOneImage()
continue
}
results.failed(image: image)
if image.type == .avif {
avifImagesToGenerate.append(image)
} else {
newImagesToGenerate.append(image)
}
}
func generate(images: [ImageVersion]) {
for image in images {
guard shouldGenerateWebsite else { return }
defer { didFinishOneImage() }
if imageGenerator.generate(version: image) {
results.created(outputFile: image.outputPath)
continue
}
results.failed(image: image)
}
}
generate(images: newImagesToGenerate)
generate(images: avifImagesToGenerate)
if completed != count {
print("Expected \(count) images processed, but only \(completed) were")
}
}

View File

@ -71,6 +71,9 @@ struct GenerationContentView: View {
GenerationStringIssuesView(
text: "unsaved output files",
items: $content.results.unsavedOutputFiles)
GenerationStringIssuesView(
text: "failed image generations",
items: $content.results.failedImages) { $0.outputPath }
GenerationStringIssuesView(
text: "missing files",
items: $content.results.missingFiles)