Skip to content

Commit

Permalink
adding BaseURLSite
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Aug 3, 2023
1 parent 4953738 commit 0de8805
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
19 changes: 19 additions & 0 deletions Sources/ContributeWordPress/Decoder/BaseURLSite.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation
import SyndiKit

protocol BaseURLSite {
var link: URL { get }
var baseBlogURL: URL? { get }
}

extension BaseURLSite {
public var baseURL: URL {
baseBlogURL ?? link
}

Check warning on line 12 in Sources/ContributeWordPress/Decoder/BaseURLSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/BaseURLSite.swift#L10-L12

Added lines #L10 - L12 were not covered by tests
}

extension RSSChannel: BaseURLSite {
var baseBlogURL: URL? {
wpBaseBlogURL
}

Check warning on line 18 in Sources/ContributeWordPress/Decoder/BaseURLSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/BaseURLSite.swift#L16-L18

Added lines #L16 - L18 were not covered by tests
}
26 changes: 15 additions & 11 deletions Sources/ContributeWordPress/Decoder/WordPressSite.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import SyndiKit

public struct WordPressSite {
public struct WordPressSite: BaseURLSite {
public static let wpContentUploadsRelativePath = "wp-content/uploads"
public init(
title: String,
Expand Down Expand Up @@ -61,9 +61,8 @@ extension WordPressSite {
channel: RSSChannel,
relativeResourcePath: String
) throws {
let baseURL = channel.wpBaseBlogURL ?? channel.link
let assetsImagesRegex = try Self.defaultAssetsImagesRegex(
forAssetSiteURL: baseURL,
forSite: channel,
relativeResourcePath: relativeResourcePath
)
self.init(
Expand All @@ -78,21 +77,26 @@ extension WordPressSite {
)
}

Check warning on line 78 in Sources/ContributeWordPress/Decoder/WordPressSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/WordPressSite.swift#L63-L78

Added lines #L63 - L78 were not covered by tests

public static func defaultAssetsImagesRegex(
static func defaultAssetsImagesRegex(
forSite site: BaseURLSite,
relativeResourcePath: String = WordPressSite.wpContentUploadsRelativePath
) throws -> NSRegularExpression {
try Self.defaultAssetsImagesRegex(
forAssetSiteURL: site.baseURL,
relativeResourcePath: relativeResourcePath
)
}

Check warning on line 88 in Sources/ContributeWordPress/Decoder/WordPressSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/WordPressSite.swift#L83-L88

Added lines #L83 - L88 were not covered by tests

static func defaultAssetsImagesRegex(
forAssetSiteURL assetSiteURL: URL,
relativeResourcePath: String = WordPressSite.wpContentUploadsRelativePath
) throws -> NSRegularExpression {
try NSRegularExpression(pattern: "\(assetSiteURL)/\(relativeResourcePath)([^\"]+)")
}

Check warning on line 95 in Sources/ContributeWordPress/Decoder/WordPressSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/WordPressSite.swift#L93-L95

Added lines #L93 - L95 were not covered by tests

public var importDirectoryName: String {
baseBlogURL?.firstHostComponent ??
link.firstHostComponent ??
var importDirectoryName: String {
baseURL.firstHostComponent ??
baseSiteURL?.firstHostComponent ??
"default"
}

Check warning on line 101 in Sources/ContributeWordPress/Decoder/WordPressSite.swift

View check run for this annotation

Codecov / codecov/patch

Sources/ContributeWordPress/Decoder/WordPressSite.swift#L97-L101

Added lines #L97 - L101 were not covered by tests

public var baseURL: URL {
baseBlogURL ?? link
}
}

0 comments on commit 0de8805

Please sign in to comment.