diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index d41e206b..27de5567 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -94,6 +94,9 @@ private extension PodcastFeedGenerator { let title = item.rssTitle let metadata = item.metadata.podcast + let imageURL = item.imagePath.flatMap { path in + URL(string: path.absoluteString) + } return .item( .guid(for: item, site: context.site), @@ -107,7 +110,7 @@ private extension PodcastFeedGenerator { .summary(item.description), .explicit(metadata?.isExplicit ?? false), .duration(audioDuration), - .image(config.imageURL), + .image(imageURL ?? config.imageURL), .unwrap(metadata?.episodeNumber, Node.episodeNumber), .unwrap(metadata?.seasonNumber, Node.seasonNumber), .audio( diff --git a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift index e836f52d..064aea9d 100644 --- a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift +++ b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift @@ -162,6 +162,25 @@ final class PodcastFeedGenerationTests: PublishTestCase { let feedB = try folder.file(at: "Output/feed.rss").readAsString() XCTAssertNotEqual(feedA, feedB) } + + func testUseOptionalItemImageIfAvailableDefaultToConfigImage() throws { + let folder = try Folder.createTemporary() + + try generateFeed(in: folder, content: [ + "one/a.md": """ + \(makeStubbedAudioMetadata(including:"image: image-item.png")) + # Image included + """, + "one/b": """ + \(makeStubbedAudioMetadata()) + # Image not included + """ + ]) + + let feed = try folder.file(at: "Output/feed.rss").readAsString() + XCTAssertTrue(feed.contains("image.png")) + XCTAssertTrue(feed.contains("image-item.png")) + } } private extension PodcastFeedGenerationTests {