Skip to content

Commit

Permalink
Add Site and Blog URL from WordPress (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion authored Aug 3, 2023
1 parent 238c8d8 commit 67f398a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SyndiKit/Formats/Feeds/RSS/Enclosure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/SyndiKit/Formats/Feeds/RSS/RSSChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
}

Expand Down
16 changes: 16 additions & 0 deletions Tests/SyndiKitTests/WordpressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 67f398a

Please sign in to comment.