diff --git a/WebsiteGenerator/Generic/Element.swift b/WebsiteGenerator/Generic/Element.swift index f7f16a8..89dc2af 100644 --- a/WebsiteGenerator/Generic/Element.swift +++ b/WebsiteGenerator/Generic/Element.swift @@ -130,8 +130,8 @@ struct Element { self.inputFolder = folder self.path = "" - let source = "root" - guard let metadata = try GenericMetadata(path: nil, with: context) else { + let source = GenericMetadata.metadataFileName + guard let metadata = try GenericMetadata(source: source, with: context) else { return nil } @@ -166,16 +166,17 @@ struct Element { } self.elements = try subFolders.compactMap { subFolder in let s = (source.unwrapped { $0 + "/" } ?? "") + subFolder.lastPathComponent - return try Element(parent: self, folder: subFolder, with: context, source: s) + return try Element(parent: self, folder: subFolder, with: context, path: s) } } - init?(parent: Element, folder: URL, with: Context, source: String) throws { + init?(parent: Element, folder: URL, with: Context, path: String) throws { let validation = context.validation self.inputFolder = folder - self.path = source + self.path = path - guard let metadata = try GenericMetadata(path: source, with: context) else { + let source = path + "/" + GenericMetadata.metadataFileName + guard let metadata = try GenericMetadata(source: source, with: context) else { return nil } self.author = metadata.author ?? parent.author @@ -203,7 +204,7 @@ struct Element { // TODO: Propagate external files from the parent if subpath matches? self.externalFiles = metadata.externalFiles ?? [] self.requiredFiles = metadata.requiredFiles ?? [] - self.thumbnailStyle = validation.thumbnailStyle(metadata.state, source: source) + self.thumbnailStyle = validation.thumbnailStyle(metadata.thumbnailStyle, source: source) self.useManualSorting = metadata.useManualSorting ?? false self.overviewItemCount = metadata.overviewItemCount ?? parent.overviewItemCount self.languages = parent.languages.compactMap { parentData in @@ -222,7 +223,7 @@ struct Element { .forEach { validation.add(warning: "Language '\($0)' not found in parent, so not generated", source: source) } - try self.readElements(in: folder, source: source, with: context) + try self.readElements(in: folder, source: path, with: context) } } diff --git a/WebsiteGenerator/Generic/ErrorOutput.swift b/WebsiteGenerator/Generic/ErrorOutput.swift index 0ddc04f..3732509 100644 --- a/WebsiteGenerator/Generic/ErrorOutput.swift +++ b/WebsiteGenerator/Generic/ErrorOutput.swift @@ -2,12 +2,28 @@ import Foundation final class ErrorOutput { + private enum LogLevel: String { + case error = "ERROR" + case warning = "WARNING" + case info = "INFO" + } + init() { } + private func add(_ type: LogLevel, item: ContentError) { + let errorText: String + if let err = item.error { + errorText = ", Error: \(err.localizedDescription)" + } else { + errorText = "" + } + print("[\(type.rawValue)] \(item.reason), Source: \(item.source)\(errorText)") + } + func add(error: ContentError) { - print("[ERROR] Reason: \(error.reason), Source: \(error.source), Error: \(error.error?.localizedDescription ?? "nil")") + add(.error, item: error) } func add(error reason: String, source: String, error: Error? = nil) { @@ -15,7 +31,7 @@ final class ErrorOutput { } func add(warning: ContentError) { - print("[WARNING] Reason: \(warning.reason), Source: \(warning.source), Error: \(warning.error?.localizedDescription ?? "nil")") + add(.warning, item: warning) } func add(warning reason: String, source: String, error: Error? = nil) { @@ -23,7 +39,7 @@ final class ErrorOutput { } func add(info: ContentError) { - print("[INFO] Reason: \(info.reason), Source: \(info.source), Error: \(info.error?.localizedDescription ?? "nil")") + add(.info, item: info) } func add(info reason: String, source: String, error: Error? = nil) { diff --git a/WebsiteGenerator/Generic/GenericMetadata.swift b/WebsiteGenerator/Generic/GenericMetadata.swift index 914b812..290b413 100644 --- a/WebsiteGenerator/Generic/GenericMetadata.swift +++ b/WebsiteGenerator/Generic/GenericMetadata.swift @@ -136,14 +136,12 @@ extension GenericMetadata { /** Decode metadata in a folder. - - Parameter path: The path to the element folder, relative to the source root + - Parameter source: The path to the metadata file, relative to the source root - Parameter context: The context for the element (validation, file access, etc.) - Note: The decoding routine also checks for unknown properties, and writes them to the output. */ - init?(path: String?, with context: Context) throws { - let source = path ?? "root" - let metadataPath = (path.unwrapped { $0 + "/" } ?? "") + GenericMetadata.metadataFileName - guard let data = try context.fileSystem.loadDataContent(inputPath: metadataPath) else { + init?(source: String, with context: Context) throws { + guard let data = try context.fileSystem.loadDataContent(inputPath: source) else { return nil }