Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podcast feed generator episode image feature #119

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Publish/Internal/PodcastFeedGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -107,7 +110,7 @@ private extension PodcastFeedGenerator {
.summary(item.description),
.explicit(metadata?.isExplicit ?? false),
.duration(audioDuration),
.image(config.imageURL),
.image(imageURL ?? config.imageURL),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to exclude the image tag altogether when the item has no specific image?

As far as I've been able to tell, all clients will fall back to the main <itunes:image> at the channel level when the episode has no custom artwork. For shows with lots of episodes, having these duplicate tags in the feed add up and make the feed larger than it needs to be.

.unwrap(metadata?.episodeNumber, Node.episodeNumber),
.unwrap(metadata?.seasonNumber, Node.seasonNumber),
.audio(
Expand Down
19 changes: 19 additions & 0 deletions Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down