Add path parameter to image generation

This commit is contained in:
Christoph Hagen 2022-09-18 16:47:13 +02:00
parent 763b90f689
commit 3872a3e419
5 changed files with 15 additions and 3 deletions

View File

@ -228,7 +228,6 @@ final class FileSystem {
} }
@discardableResult @discardableResult
func requireImage(source: String, destination: String, width: Int, desiredHeight: Int? = nil) -> NSSize {
let height = desiredHeight.unwrapped(CGFloat.init) let height = desiredHeight.unwrapped(CGFloat.init)
let sourceUrl = input.appendingPathComponent(source) let sourceUrl = input.appendingPathComponent(source)
let image = ImageOutput(source: source, width: width, desiredHeight: desiredHeight) let image = ImageOutput(source: source, width: width, desiredHeight: desiredHeight)
@ -266,6 +265,7 @@ final class FileSystem {
imageTasks[destination] = image imageTasks[destination] = image
} }
return scaledSize return scaledSize
func requireImage(source: String, destination: String, requiredBy path: String, width: Int, desiredHeight: Int? = nil) -> NSSize {
} }
func createImages() { func createImages() {

View File

@ -109,11 +109,19 @@ struct PageContentGenerator {
private func handleImage(page: Element, file: String, rightTitle: String?, leftTitle: String?) -> String { private func handleImage(page: Element, file: String, rightTitle: String?, leftTitle: String?) -> String {
let imagePath = page.pathRelativeToRootForContainedInputFile(file) let imagePath = page.pathRelativeToRootForContainedInputFile(file)
let size = files.requireImage(source: imagePath, destination: imagePath, width: configuration.pageImageWidth) let size = files.requireImage(
source: imagePath,
destination: imagePath,
requiredBy: page.path,
width: configuration.pageImageWidth)
let imagePath2x = imagePath.insert("@2x", beforeLast: ".") let imagePath2x = imagePath.insert("@2x", beforeLast: ".")
let file2x = file.insert("@2x", beforeLast: ".") let file2x = file.insert("@2x", beforeLast: ".")
files.requireImage(source: imagePath, destination: imagePath2x, width: 2 * configuration.pageImageWidth) files.requireImage(
source: imagePath,
destination: imagePath2x,
requiredBy: page.path,
width: 2 * configuration.pageImageWidth)
let content: [PageImageTemplate.Key : String] = [ let content: [PageImageTemplate.Key : String] = [
.image: file, .image: file,

View File

@ -27,6 +27,7 @@ struct PageHeadGenerator {
files.requireImage( files.requireImage(
source: sourceImagePath, source: sourceImagePath,
destination: destinationImagePath, destination: destinationImagePath,
requiredBy: page.path,
width: PageHeadGenerator.linkPreviewDesiredImageWidth) width: PageHeadGenerator.linkPreviewDesiredImageWidth)
content[.image] = factory.html.linkPreviewImage(file: linkPreviewImageName) content[.image] = factory.html.linkPreviewImage(file: linkPreviewImageName)
} }

View File

@ -53,6 +53,7 @@ struct SiteGenerator {
files.requireImage( files.requireImage(
source: $0.sourcePath, source: $0.sourcePath,
destination: $0.destinationPath, destination: $0.destinationPath,
requiredBy: element.path,
width: $0.desiredWidth, width: $0.desiredWidth,
desiredHeight: $0.desiredHeight) desiredHeight: $0.desiredHeight)
} }

View File

@ -39,6 +39,7 @@ struct ThumbnailListGenerator {
files.requireImage( files.requireImage(
source: fullThumbnailPath, source: fullThumbnailPath,
destination: fullThumbnailPath, destination: fullThumbnailPath,
requiredBy: item.path,
width: style.width, width: style.width,
desiredHeight: style.height) desiredHeight: style.height)
@ -46,6 +47,7 @@ struct ThumbnailListGenerator {
files.requireImage( files.requireImage(
source: fullThumbnailPath, source: fullThumbnailPath,
destination: fullThumbnailPath.insert("@2x", beforeLast: "."), destination: fullThumbnailPath.insert("@2x", beforeLast: "."),
requiredBy: item.path,
width: style.width * 2, width: style.width * 2,
desiredHeight: style.height * 2) desiredHeight: style.height * 2)