diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-01-08 15:18:00 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-01-08 15:18:00 -0800 |
| commit | f87ae3b315e20ac31426782d7f40f8977a36e5b9 (patch) | |
| tree | 7caa3fd1d798be23a7c27239ccc01ecb902160d0 | |
| parent | e9bae0328801d5a056f33beb0f764c6d35e518a2 (diff) | |
Add Markdown display for news articles to support rich text, images, links, tables, etc.
| -rw-r--r-- | Hotline.xcodeproj/project.pbxproj | 27 | ||||
| -rw-r--r-- | Hotline.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 23 | ||||
| -rw-r--r-- | Hotline/Models/NewsInfo.swift | 4 | ||||
| -rw-r--r-- | Hotline/macOS/NewsView.swift | 24 |
4 files changed, 66 insertions, 12 deletions
diff --git a/Hotline.xcodeproj/project.pbxproj b/Hotline.xcodeproj/project.pbxproj index 0574111..8358f3b 100644 --- a/Hotline.xcodeproj/project.pbxproj +++ b/Hotline.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ DAB4D8802B4C8E9A0048A05C /* URLAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB4D87F2B4C8E9A0048A05C /* URLAdditions.swift */; }; DAB4D8822B4C8FED0048A05C /* FileIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB4D8812B4C8FED0048A05C /* FileIconView.swift */; }; DAB4D8842B4CABEF0048A05C /* DataAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAB4D8832B4CABEF0048A05C /* DataAdditions.swift */; }; + DAB4D8872B4CB3610048A05C /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = DAB4D8862B4CB3610048A05C /* MarkdownUI */; }; DABFCC292B1530DC009F40D2 /* FoundationExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DABFCC282B1530DC009F40D2 /* FoundationExtensions.swift */; }; DAC002192B21630900A6C290 /* SwiftUIExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC002182B21630900A6C290 /* SwiftUIExtensions.swift */; }; DADDB28B2B22B31F0024040D /* Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DADDB28A2B22B31F0024040D /* Tracker.swift */; }; @@ -110,6 +111,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + DAB4D8872B4CB3610048A05C /* MarkdownUI in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -258,6 +260,9 @@ dependencies = ( ); name = Hotline; + packageProductDependencies = ( + DAB4D8862B4CB3610048A05C /* MarkdownUI */, + ); productName = Hotline; productReference = DA9CAFB72B126D5700CDA197 /* Hotline.app */; productType = "com.apple.product-type.application"; @@ -286,6 +291,9 @@ Base, ); mainGroup = DA9CAFAE2B126D5700CDA197; + packageReferences = ( + DAB4D8852B4CB3610048A05C /* XCRemoteSwiftPackageReference "swift-markdown-ui" */, + ); productRefGroup = DA9CAFB82B126D5700CDA197 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -580,6 +588,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + DAB4D8852B4CB3610048A05C /* XCRemoteSwiftPackageReference "swift-markdown-ui" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/gonzalezreal/swift-markdown-ui"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.3.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + DAB4D8862B4CB3610048A05C /* MarkdownUI */ = { + isa = XCSwiftPackageProductDependency; + package = DAB4D8852B4CB3610048A05C /* XCRemoteSwiftPackageReference "swift-markdown-ui" */; + productName = MarkdownUI; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = DA9CAFAF2B126D5700CDA197 /* Project object */; } diff --git a/Hotline.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Hotline.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..a1afabf --- /dev/null +++ b/Hotline.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,23 @@ +{ + "pins" : [ + { + "identity" : "networkimage", + "kind" : "remoteSourceControl", + "location" : "https://github.com/gonzalezreal/NetworkImage", + "state" : { + "revision" : "7aff8d1b31148d32c5933d75557d42f6323ee3d1", + "version" : "6.0.0" + } + }, + { + "identity" : "swift-markdown-ui", + "kind" : "remoteSourceControl", + "location" : "https://github.com/gonzalezreal/swift-markdown-ui", + "state" : { + "revision" : "ae799d015a5374708f7b4c85f3294c05f2a564e2", + "version" : "2.3.0" + } + } + ], + "version" : 2 +} diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift index daab71f..f95cba1 100644 --- a/Hotline/Models/NewsInfo.swift +++ b/Hotline/Models/NewsInfo.swift @@ -15,6 +15,7 @@ enum NewsInfoType { let categoryID: UUID? let articleID: UInt? + let parentID: UInt? let path: [String] var expanded: Bool = false @@ -27,6 +28,7 @@ enum NewsInfoType { init(hotlineNewsCategory: HotlineNewsCategory) { self.categoryID = hotlineNewsCategory.id self.articleID = nil + self.parentID = nil self.name = hotlineNewsCategory.name self.count = UInt(hotlineNewsCategory.count) self.path = hotlineNewsCategory.path @@ -41,6 +43,8 @@ enum NewsInfoType { init(hotlineNewsArticle: HotlineNewsArticle) { self.articleID = UInt(hotlineNewsArticle.id) + self.parentID = hotlineNewsArticle.parentID == 0 ? nil : UInt(hotlineNewsArticle.parentID) + print(hotlineNewsArticle.parentID) self.categoryID = nil self.name = hotlineNewsArticle.title self.count = 0 diff --git a/Hotline/macOS/NewsView.swift b/Hotline/macOS/NewsView.swift index 45bae68..daeb45b 100644 --- a/Hotline/macOS/NewsView.swift +++ b/Hotline/macOS/NewsView.swift @@ -1,5 +1,5 @@ import SwiftUI -import UniformTypeIdentifiers +import MarkdownUI struct NewsItemView: View { @Environment(Hotline.self) private var model: Hotline @@ -24,7 +24,7 @@ struct NewsItemView: View { }() var body: some View { - HStack { + HStack(alignment: .center, spacing: 6) { if news.type == .bundle || news.type == .category { Button { news.expanded.toggle() @@ -40,15 +40,14 @@ struct NewsItemView: View { .padding(.leading, 4) } else if news.type == .article { -// HStack(alignment: .center) { -// Text(Image(systemName: "quote.opening")) -// .font(.system(size: 12)) -// .opacity(0.5) -// .frame(alignment: .centerFirstTextBaseline) - -// Image(systemName: "quote.opening") -// } -// .frame(width: 14) + if news.parentID != nil { + Image(systemName: "arrowshape.turn.up.left.fill") + .resizable() + .renderingMode(.template) + .scaledToFit() + .frame(width: 10) + .foregroundStyle(.secondary) + } } Text(news.name) .fontWeight((news.type == .bundle || news.type == .category) ? .bold : .regular) @@ -203,7 +202,8 @@ struct NewsView: View { Divider() if let newsText = self.articleText { - Text(newsText) + Markdown(newsText) +// Text(newsText) .textSelection(.enabled) .lineSpacing(4) .padding(.top, 16) |