From 668720a272c19df526af7636f2315f4db52f2581 Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Fri, 10 Jan 2020 07:54:09 -0300 Subject: [PATCH 1/7] Fixed SectionID rawvalue bug in item. --- Sources/Publish/API/Item.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Publish/API/Item.swift b/Sources/Publish/API/Item.swift index 1565b513..6350b7f8 100644 --- a/Sources/Publish/API/Item.swift +++ b/Sources/Publish/API/Item.swift @@ -56,6 +56,6 @@ internal extension Item { private extension Item { func makeAbsolutePath() -> Path { - "\(sectionID)/\(relativePath)" + "\(sectionID.rawValue)/\(relativePath)" } } From b22df51c77912b925168ac3029009a9d905c315b Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Fri, 10 Jan 2020 14:30:45 -0300 Subject: [PATCH 2/7] Adjusted tests to check for SecionID.rawvalue bug. --- Tests/PublishTests/Infrastructure/PublishTestCase.swift | 1 + Tests/PublishTests/Infrastructure/WebsiteStub.swift | 2 +- Tests/PublishTests/Tests/HTMLGenerationTests.swift | 9 ++++++++- Tests/PublishTests/Tests/WebsiteTests.swift | 5 +++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Tests/PublishTests/Infrastructure/PublishTestCase.swift b/Tests/PublishTests/Infrastructure/PublishTestCase.swift index 84e0f6a8..c9f12ef5 100644 --- a/Tests/PublishTests/Infrastructure/PublishTestCase.swift +++ b/Tests/PublishTests/Infrastructure/PublishTestCase.swift @@ -88,6 +88,7 @@ class PublishTestCase: XCTestCase { "one/index.html", "two/index.html", "three/index.html", + "custom-raw-value/index.html", "tags/index.html" ] diff --git a/Tests/PublishTests/Infrastructure/WebsiteStub.swift b/Tests/PublishTests/Infrastructure/WebsiteStub.swift index 84195e29..09c3638f 100644 --- a/Tests/PublishTests/Infrastructure/WebsiteStub.swift +++ b/Tests/PublishTests/Infrastructure/WebsiteStub.swift @@ -10,7 +10,7 @@ import Plot class WebsiteStub { enum SectionID: String, WebsiteSectionID { - case one, two, three + case one, two, three, customRawValue = "custom-raw-value" } var url = URL(string: "https://swiftbysundell.com")! diff --git a/Tests/PublishTests/Tests/HTMLGenerationTests.swift b/Tests/PublishTests/Tests/HTMLGenerationTests.swift index b836ba49..d4382acd 100644 --- a/Tests/PublishTests/Tests/HTMLGenerationTests.swift +++ b/Tests/PublishTests/Tests/HTMLGenerationTests.swift @@ -206,10 +206,12 @@ final class HTMLGenerationTests: PublishTestCase { expectedHTML: [ "one/index.html": "one", "two/index.html": "two", - "three/index.html": "three" + "three/index.html": "three", + "custom-raw-value/index.html": "custom-raw-value" ] ) } + func testNotGeneratingTagHTMLForIncompatibleTheme() throws { htmlFactory.makeTagListHTML = nil @@ -225,6 +227,7 @@ final class HTMLGenerationTests: PublishTestCase { "one/index.html": "", "two/index.html": "", "three/index.html": "", + "custom-raw-value/index.html": "", "one/item/index.html": "" ], allowWhitelistedOutputFiles: false @@ -245,6 +248,7 @@ final class HTMLGenerationTests: PublishTestCase { "one/index.html": "", "two/index.html": "", "three/index.html": "", + "custom-raw-value/index.html": "", "one/item/index.html": "" ], allowWhitelistedOutputFiles: false @@ -257,6 +261,7 @@ final class HTMLGenerationTests: PublishTestCase { try publishWebsite(in: folder, using: [ .addItem(Item.stub(withPath: "item").setting(\.tags, to: ["tag"])), + .addItem(Item.stub(withPath: "rawValueItem", sectionID: .customRawValue).setting(\.tags, to: ["tag"])), .generateHTML(withTheme: theme, fileMode: .standAloneFiles) ]) @@ -267,7 +272,9 @@ final class HTMLGenerationTests: PublishTestCase { "one/index.html": "", "two/index.html": "", "three/index.html": "", + "custom-raw-value/index.html": "", "one/item.html": "", + "custom-raw-value/rawValueItem.html": "", "tags/index.html": "", "tags/tag.html": "" ], diff --git a/Tests/PublishTests/Tests/WebsiteTests.swift b/Tests/PublishTests/Tests/WebsiteTests.swift index 681b9544..bf7df634 100644 --- a/Tests/PublishTests/Tests/WebsiteTests.swift +++ b/Tests/PublishTests/Tests/WebsiteTests.swift @@ -27,6 +27,10 @@ final class WebsiteTests: PublishTestCase { func testPathForSectionID() { XCTAssertEqual(website.path(for: .one), "one") } + + func testPathForSectionIDWithRawValue() { + XCTAssertEqual(website.path(for: .customRawValue), "custom-raw-value") + } func testDefaultPathForTag() { let tag = Tag("some tag") @@ -85,6 +89,7 @@ extension WebsiteTests { ("testDefaultTagListPath", testDefaultTagListPath), ("testCustomTagListPath", testCustomTagListPath), ("testPathForSectionID", testPathForSectionID), + ("testPathForSectionIDWithRawValue", testPathForSectionIDWithRawValue), ("testDefaultPathForTag", testDefaultPathForTag), ("testCustomPathForTag", testCustomPathForTag), ("testDefaultURLForTag", testDefaultURLForTag), From 80f56dc3bd99a6cc4cda08a2be144fb67e8ae68b Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Thu, 12 Mar 2020 14:51:17 -0300 Subject: [PATCH 3/7] Added title to PodcastFeedConfiguration so that podcast titles are no longer limited to being the same as the site title. --- Sources/Publish/API/PodcastFeedConfiguration.swift | 4 ++++ Sources/Publish/Internal/PodcastFeedGenerator.swift | 2 +- Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Sources/Publish/API/PodcastFeedConfiguration.swift b/Sources/Publish/API/PodcastFeedConfiguration.swift index d97b805c..d664e492 100644 --- a/Sources/Publish/API/PodcastFeedConfiguration.swift +++ b/Sources/Publish/API/PodcastFeedConfiguration.swift @@ -11,6 +11,8 @@ import Plot /// using the `generatePodcastFeed` step. To use a default implementation, /// use `PodcastFeedConfiguration.default`. public struct PodcastFeedConfiguration: FeedConfiguration { + /// A title for the podcast. + public var title: String public var targetPath: Path public var ttlInterval: TimeInterval public var maximumItemCount: Int @@ -53,6 +55,7 @@ public struct PodcastFeedConfiguration: FeedConfiguration { /// - Parameter newFeedURL: Any new feed URL for the podcast. /// - Parameter indentation: How the feed should be indented. public init( + title: String, targetPath: Path, ttlInterval: TimeInterval = 250, maximumItemCount: Int = .max, @@ -68,6 +71,7 @@ public struct PodcastFeedConfiguration: FeedConfiguration { newFeedURL: URL? = nil, indentation: Indentation.Kind? = nil ) { + self.title = title self.targetPath = targetPath self.ttlInterval = ttlInterval self.maximumItemCount = maximumItemCount diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index 53ef0775..4c37133a 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -50,7 +50,7 @@ private extension PodcastFeedGenerator { section: Section) throws -> PodcastFeed { try PodcastFeed( .unwrap(config.newFeedURL, Node.newFeedURL), - .title(context.site.name), + .title(config.title), .description(config.description), .link(context.site.url(for: section)), .language(context.site.language), diff --git a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift index 68bddca0..5ceb7f83 100644 --- a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift +++ b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift @@ -163,6 +163,7 @@ private extension PodcastFeedGenerationTests { func makeConfigStub() throws -> Configuration { try Configuration( + title:"Appleseed's Podcast", targetPath: .defaultForRSSFeed, imageURL: require(URL(string: "image.png")), copyrightText: "John Appleseed 2019", From db4f103801fdb399d880e571bea152924fd707c8 Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Wed, 22 Apr 2020 13:48:43 -0300 Subject: [PATCH 4/7] Made title in PodcastFeedConfiguration optional so that it's backwards compatible. --- Sources/Publish/API/PodcastFeedConfiguration.swift | 4 ++-- Sources/Publish/Internal/PodcastFeedGenerator.swift | 2 +- Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Publish/API/PodcastFeedConfiguration.swift b/Sources/Publish/API/PodcastFeedConfiguration.swift index d664e492..2f7ea9cd 100644 --- a/Sources/Publish/API/PodcastFeedConfiguration.swift +++ b/Sources/Publish/API/PodcastFeedConfiguration.swift @@ -12,7 +12,7 @@ import Plot /// use `PodcastFeedConfiguration.default`. public struct PodcastFeedConfiguration: FeedConfiguration { /// A title for the podcast. - public var title: String + public var title: String? public var targetPath: Path public var ttlInterval: TimeInterval public var maximumItemCount: Int @@ -55,7 +55,7 @@ public struct PodcastFeedConfiguration: FeedConfiguration { /// - Parameter newFeedURL: Any new feed URL for the podcast. /// - Parameter indentation: How the feed should be indented. public init( - title: String, + title: String? = nil, targetPath: Path, ttlInterval: TimeInterval = 250, maximumItemCount: Int = .max, diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index 4c37133a..3f103e77 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -50,7 +50,7 @@ private extension PodcastFeedGenerator { section: Section) throws -> PodcastFeed { try PodcastFeed( .unwrap(config.newFeedURL, Node.newFeedURL), - .title(config.title), + .title(config.title != nil ? config.title! : context.site.name), .description(config.description), .link(context.site.url(for: section)), .language(context.site.language), diff --git a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift index 5ceb7f83..68bddca0 100644 --- a/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift +++ b/Tests/PublishTests/Tests/PodcastFeedGenerationTests.swift @@ -163,7 +163,6 @@ private extension PodcastFeedGenerationTests { func makeConfigStub() throws -> Configuration { try Configuration( - title:"Appleseed's Podcast", targetPath: .defaultForRSSFeed, imageURL: require(URL(string: "image.png")), copyrightText: "John Appleseed 2019", From 329649095c40da15747e5e7a7b78c3ee41524008 Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Wed, 30 Jun 2021 14:16:52 -0300 Subject: [PATCH 5/7] Added feature to use item image in podcast generation as the episode image. --- .../Internal/PodcastFeedGenerator.swift | 9 +++++++- .../Tests/PodcastFeedGenerationTests.swift | 22 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index 4ee39a7c..664170e7 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -90,6 +90,13 @@ private extension PodcastFeedGenerator { guard let audioSize = audio.byteSize else { throw PodcastError(path: item.path, reason: .missingAudioSize) } + + var imageUrl = config.imageURL + if let imagePath = item.imagePath { + if let url = URL(string: imagePath.absoluteString){ + imageUrl = url + } + } let title = item.rssTitle let metadata = item.metadata.podcast @@ -106,7 +113,7 @@ private extension PodcastFeedGenerator { .summary(item.description), .explicit(metadata?.isExplicit ?? false), .duration(audioDuration), - .image(config.imageURL), + .image(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 da457aae..16df39a7 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")) + } } extension PodcastFeedGenerationTests { @@ -173,7 +192,8 @@ extension PodcastFeedGenerationTests { ("testItemPrefixAndSuffix", testItemPrefixAndSuffix), ("testReusingPreviousFeedIfNoItemsWereModified", testReusingPreviousFeedIfNoItemsWereModified), ("testNotReusingPreviousFeedIfConfigChanged", testNotReusingPreviousFeedIfConfigChanged), - ("testNotReusingPreviousFeedIfItemWasAdded", testNotReusingPreviousFeedIfItemWasAdded) + ("testNotReusingPreviousFeedIfItemWasAdded", testNotReusingPreviousFeedIfItemWasAdded), + ("testUseOptionalItemImageIfAvailableDefaultToConfigImage", testUseOptionalItemImageIfAvailableDefaultToConfigImage) ] } } From 4f0d8f94360d087cbbea397c024c1140d48aa700 Mon Sep 17 00:00:00 2001 From: Joshua Goossen Date: Fri, 17 Dec 2021 22:27:33 -0300 Subject: [PATCH 6/7] Removed things unrelated to pull request --- Sources/Publish/API/PodcastFeedConfiguration.swift | 4 ---- Sources/Publish/Internal/PodcastFeedGenerator.swift | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Publish/API/PodcastFeedConfiguration.swift b/Sources/Publish/API/PodcastFeedConfiguration.swift index 2f7ea9cd..d97b805c 100644 --- a/Sources/Publish/API/PodcastFeedConfiguration.swift +++ b/Sources/Publish/API/PodcastFeedConfiguration.swift @@ -11,8 +11,6 @@ import Plot /// using the `generatePodcastFeed` step. To use a default implementation, /// use `PodcastFeedConfiguration.default`. public struct PodcastFeedConfiguration: FeedConfiguration { - /// A title for the podcast. - public var title: String? public var targetPath: Path public var ttlInterval: TimeInterval public var maximumItemCount: Int @@ -55,7 +53,6 @@ public struct PodcastFeedConfiguration: FeedConfiguration { /// - Parameter newFeedURL: Any new feed URL for the podcast. /// - Parameter indentation: How the feed should be indented. public init( - title: String? = nil, targetPath: Path, ttlInterval: TimeInterval = 250, maximumItemCount: Int = .max, @@ -71,7 +68,6 @@ public struct PodcastFeedConfiguration: FeedConfiguration { newFeedURL: URL? = nil, indentation: Indentation.Kind? = nil ) { - self.title = title self.targetPath = targetPath self.ttlInterval = ttlInterval self.maximumItemCount = maximumItemCount diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index 664170e7..04807478 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -55,7 +55,7 @@ private extension PodcastFeedGenerator { section: Section) throws -> PodcastFeed { try PodcastFeed( .unwrap(config.newFeedURL, Node.newFeedURL), - .title(config.title != nil ? config.title! : context.site.name), + .title(context.site.name), .description(config.description), .link(context.site.url(for: section)), .language(context.site.language), From a0a0b4a80fbab195fa714ef3887ff7b1c6b434ba Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 20 Apr 2022 12:30:06 +0200 Subject: [PATCH 7/7] PodcastFeedGenerator: Code style changes for episode-specific image URLs --- Sources/Publish/Internal/PodcastFeedGenerator.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/Publish/Internal/PodcastFeedGenerator.swift b/Sources/Publish/Internal/PodcastFeedGenerator.swift index 04807478..6a8d65f0 100644 --- a/Sources/Publish/Internal/PodcastFeedGenerator.swift +++ b/Sources/Publish/Internal/PodcastFeedGenerator.swift @@ -90,16 +90,12 @@ private extension PodcastFeedGenerator { guard let audioSize = audio.byteSize else { throw PodcastError(path: item.path, reason: .missingAudioSize) } - - var imageUrl = config.imageURL - if let imagePath = item.imagePath { - if let url = URL(string: imagePath.absoluteString){ - imageUrl = url - } - } 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), @@ -113,7 +109,7 @@ private extension PodcastFeedGenerator { .summary(item.description), .explicit(metadata?.isExplicit ?? false), .duration(audioDuration), - .image(imageUrl), + .image(imageURL ?? config.imageURL), .unwrap(metadata?.episodeNumber, Node.episodeNumber), .unwrap(metadata?.seasonNumber, Node.seasonNumber), .audio(