From 67f398a23ad1ca35a276295d4cf0e46c7cfc4e4f Mon Sep 17 00:00:00 2001 From: leogdion Date: Thu, 3 Aug 2023 10:53:05 -0400 Subject: [PATCH] Add Site and Blog URL from WordPress (#49) --- Package.swift | 2 +- .../SyndiKit/Formats/Feeds/RSS/Enclosure.swift | 2 +- .../SyndiKit/Formats/Feeds/RSS/RSSChannel.swift | 4 ++++ Tests/SyndiKitTests/WordpressTests.swift | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 9a78e69..c708bf2 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,7 @@ let package = Package( ) ], dependencies: [ - .package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.16.0") + .package(url: "https://github.com/CoreOffice/XMLCoder", from: "0.17.1") ], targets: [ .target( diff --git a/Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift b/Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift index 6bf27e6..5aa0655 100644 --- a/Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift +++ b/Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift @@ -12,7 +12,7 @@ public struct Enclosure: Codable { } public init(from decoder: Decoder) throws { - let container = try decoder.container(keyedBy: Self.CodingKeys) + let container = try decoder.container(keyedBy: Self.CodingKeys.self) url = try container.decode(UTF8EncodedURL.self, forKey: .url).value type = try container.decode(String.self, forKey: .type) if container.contains(.length) { diff --git a/Sources/SyndiKit/Formats/Feeds/RSS/RSSChannel.swift b/Sources/SyndiKit/Formats/Feeds/RSS/RSSChannel.swift index 42e10b7..331ba2b 100644 --- a/Sources/SyndiKit/Formats/Feeds/RSS/RSSChannel.swift +++ b/Sources/SyndiKit/Formats/Feeds/RSS/RSSChannel.swift @@ -42,6 +42,8 @@ public struct RSSChannel: Codable { public let author: Author? public let wpCategories: [WordPressElements.Category] public let wpTags: [WordPressElements.Tag] + public let wpBaseSiteURL: URL? + public let wpBaseBlogURL: URL? enum CodingKeys: String, CodingKey { case title @@ -61,6 +63,8 @@ public struct RSSChannel: Codable { case author case wpCategories = "wp:category" case wpTags = "wp:tag" + case wpBaseSiteURL = "wp:baseSiteUrl" + case wpBaseBlogURL = "wp:baseBlogUrl" } } diff --git a/Tests/SyndiKitTests/WordpressTests.swift b/Tests/SyndiKitTests/WordpressTests.swift index a9113ae..55ce6a7 100644 --- a/Tests/SyndiKitTests/WordpressTests.swift +++ b/Tests/SyndiKitTests/WordpressTests.swift @@ -3,6 +3,18 @@ import Foundation import XCTest final class WordpressTests: XCTestCase { + + static let baseSiteURLs : [String : URL] = [ + "articles" : URL(string: "https://brightdigit.com/")!, + "tutorials" : URL(string: "https://brightdigit.com/")! + ] + + + static let baseBlogURLs : [String : URL] = [ + "articles" : URL(string: "https://brightdigit.com")!, + "tutorials" : URL(string: "https://learningswift.brightdigit.com")! + ] + func testDateDecoder() { let dateDecoder = DateFormatterDecoder.RSS.decoder let result = dateDecoder.decodeString("Fri, 06 Oct 2017 17:21:35 +0000") @@ -38,6 +50,10 @@ final class WordpressTests: XCTestCase { continue } + XCTAssertNotNil(feed.channel.wpBaseSiteURL) + XCTAssertNotNil(feed.channel.wpBaseBlogURL) + XCTAssertEqual(feed.channel.wpBaseSiteURL, Self.baseSiteURLs[name]) + XCTAssertEqual(feed.channel.wpBaseBlogURL, Self.baseBlogURLs[name]) XCTAssertGreaterThan(feed.channel.wpTags.count, 0) XCTAssertGreaterThan(feed.channel.wpCategories.count, 0) let notPostIndex = feed.channel.items.firstIndex(where: {