Improve printing and image creation
This commit is contained in:
@@ -183,7 +183,7 @@ struct Element {
|
||||
self.sortIndex = log.unused(metadata.sortIndex, "sortIndex", source: source)
|
||||
self.externalFiles = metadata.externalFiles ?? []
|
||||
self.requiredFiles = metadata.requiredFiles ?? [] // Paths are already relative to root
|
||||
self.images = metadata.images?.compactMap { ManualImage(input: $0, path: "") } ?? []
|
||||
self.images = metadata.images?.compactMap { ManualImage(input: $0, path: "", log: log) } ?? []
|
||||
self.thumbnailPath = metadata.thumbnailPath ?? Element.defaultThumbnailName
|
||||
self.thumbnailStyle = log.castUnused(metadata.thumbnailStyle, "thumbnailStyle", source: source)
|
||||
self.useManualSorting = log.unused(metadata.useManualSorting, "useManualSorting", source: source)
|
||||
@@ -204,7 +204,7 @@ struct Element {
|
||||
return nil
|
||||
}
|
||||
|
||||
files.add(page: path, id: id)
|
||||
//files.add(page: path, id: id)
|
||||
self.readElements(in: folder, source: nil, log: log)
|
||||
}
|
||||
|
||||
@@ -239,13 +239,13 @@ struct Element {
|
||||
self.author = metadata.author ?? parent.author
|
||||
self.topBarTitle = log.unused(metadata.topBarTitle, "topBarTitle", source: source)
|
||||
self.date = metadata.date.unwrapped { log.cast($0, "date", source: source) }
|
||||
self.endDate = metadata.date.unwrapped { log.cast($0, "endDate", source: source) }
|
||||
self.endDate = metadata.endDate.unwrapped { log.cast($0, "endDate", source: source) }
|
||||
self.state = log.cast(metadata.state, "state", source: source)
|
||||
self.sortIndex = metadata.sortIndex
|
||||
// TODO: Propagate external files from the parent if subpath matches?
|
||||
self.externalFiles = Element.rootPaths(for: metadata.externalFiles, path: path)
|
||||
self.requiredFiles = Element.rootPaths(for: metadata.requiredFiles, path: path)
|
||||
self.images = metadata.images?.compactMap { ManualImage(input: $0, path: path) } ?? []
|
||||
self.images = metadata.images?.compactMap { ManualImage(input: $0, path: path, log: log) } ?? []
|
||||
self.thumbnailPath = metadata.thumbnailPath ?? Element.defaultThumbnailName
|
||||
self.thumbnailStyle = log.cast(metadata.thumbnailStyle, "thumbnailStyle", source: source)
|
||||
self.useManualSorting = metadata.useManualSorting ?? false
|
||||
@@ -285,9 +285,21 @@ struct Element {
|
||||
return nil
|
||||
}
|
||||
|
||||
files.add(page: path, id: id)
|
||||
//files.add(page: path, id: id)
|
||||
self.readElements(in: folder, source: path, log: log)
|
||||
}
|
||||
|
||||
func getContainedIds(log: MetadataInfoLogger) -> [String : String] {
|
||||
elements.reduce(into: [id : path]) { dict, element in
|
||||
element.getContainedIds(log: log).forEach { id, path in
|
||||
if let existing = dict[id] {
|
||||
log.error("Conflicting id with \(existing)", source: path)
|
||||
} else {
|
||||
dict[id] = path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Paths
|
||||
@@ -566,21 +578,14 @@ extension Element {
|
||||
|
||||
extension Element {
|
||||
|
||||
private var additionalHeadContentPath: String {
|
||||
var additionalHeadContentPath: String {
|
||||
path + "/head.html"
|
||||
}
|
||||
|
||||
func customHeadContent() -> String? {
|
||||
files.contentOfOptionalFile(atPath: additionalHeadContentPath, source: path)
|
||||
}
|
||||
|
||||
private var additionalFooterContentPath: String {
|
||||
var additionalFooterContentPath: String {
|
||||
path + "/footer.html"
|
||||
}
|
||||
|
||||
func customFooterContent() -> String? {
|
||||
files.contentOfOptionalFile(atPath: additionalFooterContentPath, source: path)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Debug
|
||||
@@ -607,14 +612,14 @@ extension Element {
|
||||
|
||||
let desiredHeight: Int?
|
||||
|
||||
init?(input: String, path: String) {
|
||||
init?(input: String, path: String, log: MetadataInfoLogger) {
|
||||
let parts = input.components(separatedBy: " ").filter { !$0.isEmpty }
|
||||
guard parts.count == 3 || parts.count == 4 else {
|
||||
log.add(error: "Invalid image specification, expected 'source dest width (height)", source: path)
|
||||
log.error("Invalid image specification, expected 'source dest width (height)", source: path)
|
||||
return nil
|
||||
}
|
||||
guard let width = Int(parts[2]) else {
|
||||
log.add(error: "Invalid width for image \(parts[0])", source: path)
|
||||
log.error("Invalid width for image \(parts[0])", source: path)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -626,7 +631,7 @@ extension Element {
|
||||
return
|
||||
}
|
||||
guard let height = Int(parts[3]) else {
|
||||
log.add(error: "Invalid height for image \(parts[0])", source: path)
|
||||
log.error("Invalid height for image \(parts[0])", source: path)
|
||||
return nil
|
||||
}
|
||||
self.desiredHeight = height
|
||||
@@ -716,10 +721,6 @@ extension Element {
|
||||
let destination = pathRelativeToRootForContainedInputFile("thumbnail-\(language).\(ext)")
|
||||
return (source, destination)
|
||||
}
|
||||
let thumbnailUrl = inputFolder.appendingPathComponent(thumbnailPath)
|
||||
if !thumbnailUrl.exists {
|
||||
log.add(error: "Missing thumbnail", source: path)
|
||||
}
|
||||
let source = pathRelativeToRootForContainedInputFile(thumbnailPath)
|
||||
let ext = thumbnailPath.lastComponentAfter(".")
|
||||
let destination = pathRelativeToRootForContainedInputFile("thumbnail.\(ext)")
|
||||
|
Reference in New Issue
Block a user