Allow directories for external files
This commit is contained in:
parent
1c13f4fc60
commit
a69da0fa35
@ -372,7 +372,10 @@ extension Element {
|
||||
}
|
||||
|
||||
static func rootPaths(for input: Set<String>?, path: String) -> Set<String> {
|
||||
input.unwrapped { Set($0.map { relativeToRoot(filePath: $0, folder: path) }) } ?? []
|
||||
guard let input = input else {
|
||||
return []
|
||||
}
|
||||
return Set(input.map { relativeToRoot(filePath: $0, folder: path) })
|
||||
}
|
||||
|
||||
func relativePathToFileWithPath(_ filePath: String) -> String {
|
||||
|
@ -386,7 +386,7 @@ final class FileSystem {
|
||||
let sourceUrl = input.appendingPathComponent(cleanPath)
|
||||
let destinationUrl = output.appendingPathComponent(cleanPath)
|
||||
guard sourceUrl.exists else {
|
||||
if !externalFiles.contains(file) {
|
||||
if !isExternal(file: file) {
|
||||
log.add(error: "Missing required file", source: cleanPath)
|
||||
}
|
||||
continue
|
||||
@ -403,7 +403,7 @@ final class FileSystem {
|
||||
}
|
||||
}
|
||||
for (file, source) in expectedFiles {
|
||||
guard !externalFiles.contains(file) else {
|
||||
guard !isExternal(file: file) else {
|
||||
continue
|
||||
}
|
||||
let cleanPath = cleanRelativeURL(file)
|
||||
@ -438,6 +438,42 @@ final class FileSystem {
|
||||
return result.joined(separator: "/")
|
||||
}
|
||||
|
||||
/**
|
||||
Check if a file is marked as external.
|
||||
|
||||
Also checks for sub-paths of the file, e.g if the folder `docs` is marked as external,
|
||||
then files like `docs/index.html` are also found to be external.
|
||||
- Note: All paths are either relative to root (no leading slash) or absolute paths of the domain (leading slash)
|
||||
*/
|
||||
func isExternal(file: String) -> Bool {
|
||||
// Deconstruct file path
|
||||
var path = ""
|
||||
for part in file.components(separatedBy: "/") {
|
||||
guard part != "" else {
|
||||
continue
|
||||
}
|
||||
if path == "" {
|
||||
path = part
|
||||
} else {
|
||||
path += "/" + part
|
||||
}
|
||||
if externalFiles.contains(path) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func printExternalFiles() {
|
||||
guard !externalFiles.isEmpty else {
|
||||
return
|
||||
}
|
||||
print("\(externalFiles.count) external files needed:")
|
||||
for file in externalFiles.sorted() {
|
||||
print(" " + file)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Pages
|
||||
|
||||
func isEmpty(page: String) {
|
||||
|
Loading…
Reference in New Issue
Block a user