From cb9af225f069539cc0ef6d8525339bae86d0612d Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 6 Jan 2025 10:19:51 +0100 Subject: [PATCH] Generate list of external files --- .../Blocks/AudioBlockProcessor.swift | 1 + .../Commands/AudioPlayerCommand.swift | 2 ++ .../Model/Content+Generation.swift | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHDataManagement/Generator/Blocks/AudioBlockProcessor.swift b/CHDataManagement/Generator/Blocks/AudioBlockProcessor.swift index bd994b4..4d177c7 100644 --- a/CHDataManagement/Generator/Blocks/AudioBlockProcessor.swift +++ b/CHDataManagement/Generator/Blocks/AudioBlockProcessor.swift @@ -52,6 +52,7 @@ struct AudioBlockProcessor: KeyedBlockProcessor { url: file.absoluteUrl, cover: coverImage.outputPath) + results.require(file: file) results.require(image: coverImage) results.require(footer: footer) results.require(headers: .audioPlayerJs, .audioPlayerCss) diff --git a/CHDataManagement/Generator/Commands/AudioPlayerCommand.swift b/CHDataManagement/Generator/Commands/AudioPlayerCommand.swift index 1962975..68cf7c5 100644 --- a/CHDataManagement/Generator/Commands/AudioPlayerCommand.swift +++ b/CHDataManagement/Generator/Commands/AudioPlayerCommand.swift @@ -67,7 +67,9 @@ struct AudioPlayerCommand: CommandProcessor { let coverSize = 2 * content.settings.audioPlayer.playlistCoverImageSize let coverImage = image.imageVersion(width: coverSize, height: coverSize, type: image.type) let coverUrl = coverImage.outputPath + results.require(image: coverImage) + results.require(file: audioFile) let playlistItem = AudioPlayer.PlaylistItem( index: playlist.count, diff --git a/CHDataManagement/Model/Content+Generation.swift b/CHDataManagement/Model/Content+Generation.swift index ae51721..4c449f3 100644 --- a/CHDataManagement/Model/Content+Generation.swift +++ b/CHDataManagement/Model/Content+Generation.swift @@ -12,6 +12,7 @@ extension Content { self.copyRequiredFiles() self.generateRequiredImages() self.results.recalculate() + self.generateListOfExternalFiles() self.status("Generation completed") } } @@ -279,4 +280,27 @@ extension Content { return } } + + // MARK: Additional infos + + private var externalFileListName: String { "external-files.txt" } + + private func generateListOfExternalFiles() { + let files = results.requiredFiles + .filter { $0.isExternallyStored } + + guard !files.isEmpty else { + if storage.hasFileInOutputFolder(externalFileListName) { + storage.deleteInOutputFolder(externalFileListName) + } + return + } + + let content = files + .map { $0.absoluteUrl } + .sorted() + .joined(separator: "\n") + + storage.write(content, to: externalFileListName) + } }