Determine required files from custom HTML

This commit is contained in:
Christoph Hagen
2025-07-12 09:22:33 +02:00
parent ba6097a67b
commit 43b761b593
5 changed files with 53 additions and 7 deletions

View File

@@ -49,12 +49,17 @@ final class GenerationResults: ObservableObject {
@Published
var emptyPages: Set<LocalizedPageId> = []
/// The paths to the files in the output folder, without leading slashes
@Published
var outputFiles: Set<String> = []
@Published
var unusedFilesInOutput: Set<String> = []
/// The paths to files required to be in the output folder, without leading slashes
@Published
var requiredOutputFiles: Set<String> = []
/**
The url redirects to install to prevent broken links.
@@ -126,6 +131,7 @@ final class GenerationResults: ObservableObject {
self.redirects = [:]
self.outputFiles = []
self.unusedFilesInOutput = []
self.requiredOutputFiles = []
}
for result in cache.values {
result.reset()
@@ -257,10 +263,26 @@ final class GenerationResults: ObservableObject {
}
func determineFiles(unusedIn existingFiles: Set<String>) {
let unused = existingFiles.subtracting(outputFiles)
// All paths with leading without leading slashes
let unused = existingFiles.subtracting(outputFiles).subtracting(requiredOutputFiles)
update { self.unusedFilesInOutput = unused }
}
func determineMissingRequiredFiles(existingFiles: Set<String>) {
// All paths with leading without leading slashes
// Check the files required in the output against the existing files,
// and flag missing ones
let externalFilePaths = self.externalFiles.map { $0.absoluteUrl.withLeadingSlashRemoved }
let fullFiles = existingFiles.union(externalFilePaths)
let missing = requiredOutputFiles.filter { path in
!fullFiles.contains(path) &&
!fullFiles.contains(path + ".html") &&
!fullFiles.contains(path + "/1.html")
}
update { self.requiredOutputFiles = missing }
}
func sources(forMissingPage page: String) -> [(page: LocalizedItemId, source: String)] {
var all = [(page: LocalizedItemId, source: String)]()
for (id, results) in cache {
@@ -272,6 +294,10 @@ final class GenerationResults: ObservableObject {
}
return all
}
func requiredOutputFile(_ path: String) {
update { self.requiredOutputFiles.insert(path) }
}
}
private extension Dictionary where Value == Set<LocalizedItemId> {