From fa33971fea6b872982e3b3d715662ab22b6f0b08 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 28 Aug 2023 08:13:19 -0700 Subject: [PATCH] Add FeedFinder package. --- Account/Package.swift | 4 ++- .../CloudKit/CloudKitAccountDelegate.swift | 1 + .../Feedbin/FeedbinAccountDelegate.swift | 1 + .../LocalAccount/LocalAccountDelegate.swift | 1 + .../ReaderAPI/ReaderAPIAccountDelegate.swift | 1 + Articles/Package.swift | 2 +- ArticlesDatabase/Package.swift | 2 +- FeedFinder/.gitignore | 9 +++++ FeedFinder/Package.resolved | 32 +++++++++++++++++ FeedFinder/Package.swift | 36 +++++++++++++++++++ FeedFinder/README.md | 3 ++ .../Sources}/FeedFinder/FeedFinder.swift | 4 +-- .../Sources}/FeedFinder/FeedSpecifier.swift | 11 ++++-- .../Sources}/FeedFinder/HTMLFeedFinder.swift | 0 .../FeedFinderTests/FeedFinderTests.swift | 2 ++ NetNewsWire.xcodeproj/project.pbxproj | 2 ++ Secrets/Package.swift | 2 +- 17 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 FeedFinder/.gitignore create mode 100644 FeedFinder/Package.resolved create mode 100644 FeedFinder/Package.swift create mode 100644 FeedFinder/README.md rename {Account/Sources/Account => FeedFinder/Sources}/FeedFinder/FeedFinder.swift (97%) rename {Account/Sources/Account => FeedFinder/Sources}/FeedFinder/FeedSpecifier.swift (90%) rename {Account/Sources/Account => FeedFinder/Sources}/FeedFinder/HTMLFeedFinder.swift (100%) create mode 100644 FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift diff --git a/Account/Package.swift b/Account/Package.swift index a25435770..dad306e8f 100644 --- a/Account/Package.swift +++ b/Account/Package.swift @@ -13,6 +13,7 @@ dependencies.append(contentsOf: [ .package(path: "../AccountError"), .package(path: "../Articles"), .package(path: "../ArticlesDatabase"), + .package(path: "../FeedFinder"), .package(path: "../Secrets"), .package(path: "../SyncDatabase"), .package(path: "../SyncClients/NewsBlur"), @@ -30,7 +31,7 @@ dependencies.append(contentsOf: [ let package = Package( name: "Account", defaultLocalization: "en", - platforms: [.macOS(SupportedPlatform.MacOSVersion.v13), .iOS(SupportedPlatform.IOSVersion.v16)], + platforms: [.macOS(.v13), .iOS(.v16)], products: [ .library( name: "Account", @@ -49,6 +50,7 @@ let package = Package( "AccountError", "Articles", "ArticlesDatabase", + "FeedFinder", "Secrets", "SyncDatabase", "NewsBlur", diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 7e49daf9d..67073efda 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -17,6 +17,7 @@ import Articles import ArticlesDatabase import RSWeb import Secrets +import FeedFinder enum CloudKitAccountDelegateError: LocalizedError { case invalidParameter diff --git a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift index 412803d12..292486efc 100644 --- a/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift +++ b/Account/Sources/Account/Feedbin/FeedbinAccountDelegate.swift @@ -14,6 +14,7 @@ import RSParser import RSWeb import SyncDatabase import Secrets +import FeedFinder public enum FeedbinAccountDelegateError: String, Error { case invalidParameter = "There was an invalid parameter passed." diff --git a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift index 5126eb700..339af2c58 100644 --- a/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift +++ b/Account/Sources/Account/LocalAccount/LocalAccountDelegate.swift @@ -14,6 +14,7 @@ import ArticlesDatabase import RSWeb import Secrets import AccountError +import FeedFinder public enum LocalAccountDelegateError: String, Error { case invalidParameter = "An invalid parameter was used." diff --git a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift index 2e7641aac..b5a59b722 100644 --- a/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift +++ b/Account/Sources/Account/ReaderAPI/ReaderAPIAccountDelegate.swift @@ -14,6 +14,7 @@ import SyncDatabase import Secrets import ReaderAPI import AccountError +import FeedFinder public enum ReaderAPIAccountDelegateError: LocalizedError { case unknown diff --git a/Articles/Package.swift b/Articles/Package.swift index ff88fdc2e..2de47b65a 100644 --- a/Articles/Package.swift +++ b/Articles/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( name: "Articles", - platforms: [.macOS(SupportedPlatform.MacOSVersion.v13), .iOS(SupportedPlatform.IOSVersion.v16)], + platforms: [.macOS(.v13), .iOS(.v16)], products: [ .library( name: "Articles", diff --git a/ArticlesDatabase/Package.swift b/ArticlesDatabase/Package.swift index bee51f149..321bdf053 100644 --- a/ArticlesDatabase/Package.swift +++ b/ArticlesDatabase/Package.swift @@ -21,7 +21,7 @@ dependencies.append(contentsOf: [ let package = Package( name: "ArticlesDatabase", - platforms: [.macOS(SupportedPlatform.MacOSVersion.v13), .iOS(SupportedPlatform.IOSVersion.v16)], + platforms: [.macOS(.v13), .iOS(.v16)], products: [ .library( name: "ArticlesDatabase", diff --git a/FeedFinder/.gitignore b/FeedFinder/.gitignore new file mode 100644 index 000000000..3b2981208 --- /dev/null +++ b/FeedFinder/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/FeedFinder/Package.resolved b/FeedFinder/Package.resolved new file mode 100644 index 000000000..4c0e3b60d --- /dev/null +++ b/FeedFinder/Package.resolved @@ -0,0 +1,32 @@ +{ + "pins" : [ + { + "identity" : "rscore", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Ranchero-Software/RSCore.git", + "state" : { + "revision" : "55644a3a037fed14f22ee2c0b531808f95051708", + "version" : "2.0.3" + } + }, + { + "identity" : "rsparser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Ranchero-Software/RSParser.git", + "state" : { + "revision" : "d5b50ff78905ebfaf26dd698e0e5d3ed8269dd9b", + "version" : "2.0.3" + } + }, + { + "identity" : "rsweb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Ranchero-Software/RSWeb.git", + "state" : { + "revision" : "aca2db763e3404757b273821f058bed2bbe02fcf", + "version" : "1.0.7" + } + } + ], + "version" : 2 +} diff --git a/FeedFinder/Package.swift b/FeedFinder/Package.swift new file mode 100644 index 000000000..ffc034913 --- /dev/null +++ b/FeedFinder/Package.swift @@ -0,0 +1,36 @@ +// swift-tools-version: 5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "FeedFinder", + platforms: [.macOS(.v13), .iOS(.v16)], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "FeedFinder", + targets: ["FeedFinder"]), + ], + dependencies: [ + .package(url: "https://github.com/Ranchero-Software/RSCore.git", .upToNextMajor(from: "2.0.1")), + .package(url: "https://github.com/Ranchero-Software/RSParser.git", .upToNextMajor(from: "2.0.2")), + .package(url: "https://github.com/Ranchero-Software/RSWeb.git", .upToNextMajor(from: "1.0.0")), + .package(path: "../AccountError"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "FeedFinder", + dependencies: [ + "RSCore", + "RSParser", + "RSWeb", + "AccountError" + ]), + .testTarget( + name: "FeedFinderTests", + dependencies: ["FeedFinder"]), + ] +) diff --git a/FeedFinder/README.md b/FeedFinder/README.md new file mode 100644 index 000000000..66f49a345 --- /dev/null +++ b/FeedFinder/README.md @@ -0,0 +1,3 @@ +# FeedFinder + +A description of this package. diff --git a/Account/Sources/Account/FeedFinder/FeedFinder.swift b/FeedFinder/Sources/FeedFinder/FeedFinder.swift similarity index 97% rename from Account/Sources/Account/FeedFinder/FeedFinder.swift rename to FeedFinder/Sources/FeedFinder/FeedFinder.swift index 0925af811..1a1dc88e4 100644 --- a/Account/Sources/Account/FeedFinder/FeedFinder.swift +++ b/FeedFinder/Sources/FeedFinder/FeedFinder.swift @@ -12,9 +12,9 @@ import RSWeb import RSCore import AccountError -class FeedFinder { +public final class FeedFinder { - static func find(url: URL, completion: @escaping (Result, Error>) -> Void) { + public static func find(url: URL, completion: @escaping (Result, Error>) -> Void) { downloadAddingToCache(url) { (data, response, error) in if response?.forcedStatusCode == 404 { diff --git a/Account/Sources/Account/FeedFinder/FeedSpecifier.swift b/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift similarity index 90% rename from Account/Sources/Account/FeedFinder/FeedSpecifier.swift rename to FeedFinder/Sources/FeedFinder/FeedSpecifier.swift index 4487065bb..1d2c37f18 100644 --- a/Account/Sources/Account/FeedFinder/FeedSpecifier.swift +++ b/FeedFinder/Sources/FeedFinder/FeedSpecifier.swift @@ -8,9 +8,9 @@ import Foundation -struct FeedSpecifier: Hashable { +public struct FeedSpecifier: Hashable { - enum Source: Int { + public enum Source: Int { case UserEntered = 0, HTMLHead, HTMLLink func equalToOrBetterThan(_ otherSource: Source) -> Bool { @@ -26,6 +26,13 @@ struct FeedSpecifier: Hashable { return calculatedScore() } + public init(title: String?, urlString: String, source: Source, orderFound: Int) { + self.title = title + self.urlString = urlString + self.source = source + self.orderFound = orderFound + } + func feedSpecifierByMerging(_ feedSpecifier: FeedSpecifier) -> FeedSpecifier { // Take the best data (non-nil title, better source) to create a new feed specifier; diff --git a/Account/Sources/Account/FeedFinder/HTMLFeedFinder.swift b/FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift similarity index 100% rename from Account/Sources/Account/FeedFinder/HTMLFeedFinder.swift rename to FeedFinder/Sources/FeedFinder/HTMLFeedFinder.swift diff --git a/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift b/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift new file mode 100644 index 000000000..169c02401 --- /dev/null +++ b/FeedFinder/Tests/FeedFinderTests/FeedFinderTests.swift @@ -0,0 +1,2 @@ +import XCTest +@testable import FeedFinder diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 036f72311..37ef24180 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -1344,6 +1344,7 @@ 841ABA4D20145E7300980E11 /* NothingInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NothingInspectorViewController.swift; sourceTree = ""; }; 841ABA5D20145E9200980E11 /* FolderInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderInspectorViewController.swift; sourceTree = ""; }; 841ABA5F20145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuiltinSmartFeedInspectorViewController.swift; sourceTree = ""; }; + 84208B732A9CEE2B009FE5B9 /* FeedFinder */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = FeedFinder; sourceTree = ""; }; 84216D0222128B9D0049B9B9 /* DetailWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailWebViewController.swift; sourceTree = ""; }; 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedIconDownloader.swift; sourceTree = ""; }; 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLMetadataDownloader.swift; sourceTree = ""; }; @@ -2505,6 +2506,7 @@ 51C452B22265141B00C03939 /* Frameworks */, 51CD32C624D2DEF9009ABAEF /* Account */, 8486EC402A9C2EFE007EF90D /* AccountError */, + 84208B732A9CEE2B009FE5B9 /* FeedFinder */, 8486EC3F2A9C2431007EF90D /* ReaderAPI */, 8486EC3E2A9BE083007EF90D /* NewsBlur */, 51CD32C424D2CF1D009ABAEF /* Articles */, diff --git a/Secrets/Package.swift b/Secrets/Package.swift index b622db831..c23497d42 100644 --- a/Secrets/Package.swift +++ b/Secrets/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( name: "Secrets", - platforms: [.macOS(SupportedPlatform.MacOSVersion.v11), .iOS(SupportedPlatform.IOSVersion.v14)], + platforms: [.macOS(.v13), .iOS(.v16)], products: [ .library( name: "Secrets",