Check for unused files in output folder

This commit is contained in:
Christoph Hagen
2025-02-16 14:53:00 +01:00
parent 2cad27b504
commit 6b6db702f1
9 changed files with 95 additions and 7 deletions

View File

@ -46,6 +46,12 @@ final class GenerationResults: ObservableObject {
@Published
var emptyPages: Set<LocalizedPageId> = []
@Published
var outputFiles: Set<String> = []
@Published
var unusedFilesInOutput: Set<String> = []
/**
The url redirects to install to prevent broken links.
@ -114,6 +120,8 @@ final class GenerationResults: ObservableObject {
self.unsavedOutputFiles = []
self.emptyPages = []
self.redirects = [:]
self.outputFiles = []
self.unusedFilesInOutput = []
}
for result in cache.values {
result.reset()
@ -229,6 +237,15 @@ final class GenerationResults: ObservableObject {
func redirect(from originalUrl: String, to newUrl: String) {
update { self.redirects[originalUrl] = newUrl }
}
func created(outputFile: String) {
update { self.outputFiles.insert(outputFile.withLeadingSlashRemoved) }
}
func determineFiles(unusedIn existingFiles: Set<String>) {
let unused = existingFiles.subtracting(outputFiles)
update { self.unusedFilesInOutput = unused }
}
}
private extension Dictionary where Value == Set<LocalizedItemId> {