Write AVIF image generation script
This commit is contained in:
parent
301dbad0a5
commit
6c1b473ab8
@ -656,8 +656,8 @@
|
|||||||
E2A21C342CB9A3CA0060935B /* Settings */ = {
|
E2A21C342CB9A3CA0060935B /* Settings */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
E2FE0F3D2D2B4225002963B7 /* AudioSettingsDetailView.swift */,
|
|
||||||
E29D318C2D0B2E5E0051B7F4 /* Content */,
|
E29D318C2D0B2E5E0051B7F4 /* Content */,
|
||||||
|
E2FE0F3D2D2B4225002963B7 /* AudioSettingsDetailView.swift */,
|
||||||
E29D316E2D0822720051B7F4 /* SettingsListView.swift */,
|
E29D316E2D0822720051B7F4 /* SettingsListView.swift */,
|
||||||
E29D31702D08234D0051B7F4 /* GenerationDetailView.swift */,
|
E29D31702D08234D0051B7F4 /* GenerationDetailView.swift */,
|
||||||
E25DA5942D023BCC00AEF16D /* PageSettingsDetailView.swift */,
|
E25DA5942D023BCC00AEF16D /* PageSettingsDetailView.swift */,
|
||||||
|
@ -38,8 +38,20 @@ final class ImageGenerator {
|
|||||||
|
|
||||||
private var avifCommands: Set<String> = []
|
private var avifCommands: Set<String> = []
|
||||||
|
|
||||||
func printAvifCommands() {
|
/**
|
||||||
avifCommands.sorted().forEach { print($0) }
|
Write a file to the output folder containing a script to generate all missing AVIF images.
|
||||||
|
|
||||||
|
- Note: AVIF images could be generated internally, but the process is very slow.
|
||||||
|
*/
|
||||||
|
func writeAvifCommandScript() {
|
||||||
|
guard !avifCommands.isEmpty else {
|
||||||
|
if storage.hasFileInOutputFolder("generate-images.sh") {
|
||||||
|
storage.deleteInOutputFolder("generate-images.sh")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let content = avifCommands.sorted().joined(separator: "\n")
|
||||||
|
storage.write(content, to: "generate-images.sh")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,7 +81,7 @@ extension Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imageGenerator.save()
|
imageGenerator.save()
|
||||||
imageGenerator.printAvifCommands()
|
imageGenerator.writeAvifCommandScript()
|
||||||
//let images = Set(self.images.map { $0.id })
|
//let images = Set(self.images.map { $0.id })
|
||||||
//imageGenerator.recalculateGeneratedImages(by: images)
|
//imageGenerator.recalculateGeneratedImages(by: images)
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ final class FileResource: Item {
|
|||||||
func removeGeneratedImages() {
|
func removeGeneratedImages() {
|
||||||
guard type.isImage else { return }
|
guard type.isImage else { return }
|
||||||
content.imageGenerator.removeVersions(of: id)
|
content.imageGenerator.removeVersions(of: id)
|
||||||
content.storage.deleteInOutputFolder(path: outputImageFolder)
|
content.storage.deleteInOutputFolder(outputImageFolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var failureImage: Image {
|
private var failureImage: Image {
|
||||||
@ -182,7 +182,7 @@ final class FileResource: Item {
|
|||||||
// MARK: Paths
|
// MARK: Paths
|
||||||
|
|
||||||
func removeFileFromOutputFolder() {
|
func removeFileFromOutputFolder() {
|
||||||
content.storage.deleteInOutputFolder(path: absoluteUrl)
|
content.storage.deleteInOutputFolder(absoluteUrl)
|
||||||
if type.isImage {
|
if type.isImage {
|
||||||
removeGeneratedImages()
|
removeGeneratedImages()
|
||||||
}
|
}
|
||||||
|
@ -280,9 +280,9 @@ final class Storage: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func deleteInOutputFolder(path: String) -> Bool {
|
func deleteInOutputFolder(_ relativePath: String) -> Bool {
|
||||||
guard let outputScope else { return false }
|
guard let outputScope else { return false }
|
||||||
return outputScope.deleteFile(at: path)
|
return outputScope.deleteFile(at: relativePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -400,11 +400,18 @@ final class Storage: ObservableObject {
|
|||||||
|
|
||||||
// MARK: Output files
|
// MARK: Output files
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write the content of a file to a relative path of the output folder.
|
||||||
|
*/
|
||||||
|
@discardableResult
|
||||||
func write(_ content: String, to relativeOutputPath: String) -> Bool {
|
func write(_ content: String, to relativeOutputPath: String) -> Bool {
|
||||||
guard let outputScope else { return false }
|
guard let outputScope else { return false }
|
||||||
return outputScope.write(content, to: relativeOutputPath)
|
return outputScope.write(content, to: relativeOutputPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write the data of a file to a relative path of the output folder.
|
||||||
|
*/
|
||||||
func write(_ data: Data, to relativeOutputPath: String) -> Bool {
|
func write(_ data: Data, to relativeOutputPath: String) -> Bool {
|
||||||
guard let outputScope else { return false }
|
guard let outputScope else { return false }
|
||||||
return outputScope.write(data, to: relativeOutputPath)
|
return outputScope.write(data, to: relativeOutputPath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user