From 9df483ff01586d08f605f2a81f5faaee1aa65a76 Mon Sep 17 00:00:00 2001 From: Xin Liu Date: Thu, 12 Sep 2024 06:29:52 -0700 Subject: [PATCH] Improved way to generate and use CID permalink --- Planet/Entities/MyArticleModel.swift | 6 ++++++ Planet/Views/My/MyArticleItemView.swift | 11 ++++++----- Planet/Views/Sidebar/MyPlanetSidebarItem.swift | 4 ++-- Planet/versioning.xcconfig | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Planet/Entities/MyArticleModel.swift b/Planet/Entities/MyArticleModel.swift index c1001a11..7722c77f 100644 --- a/Planet/Entities/MyArticleModel.swift +++ b/Planet/Entities/MyArticleModel.swift @@ -166,6 +166,12 @@ class MyArticleModel: ArticleModel, Codable { return URL(string: "https://dweb.link/ipns/\(planet.ipns)\(urlPath)") } } + var permalinkURL: URL? { + if let cid = planet.lastPublishedCID, cid.hasPrefix("bafy") { + return URL(string: "https://\(cid).eth.sucks\(link)") + } + return nil + } var socialImageURL: URL? { if let heroImage = getHeroImage(), let baseURL = browserURL { return baseURL.appendingPathComponent(heroImage) diff --git a/Planet/Views/My/MyArticleItemView.swift b/Planet/Views/My/MyArticleItemView.swift index 104d9da1..79880e52 100644 --- a/Planet/Views/My/MyArticleItemView.swift +++ b/Planet/Views/My/MyArticleItemView.swift @@ -229,15 +229,16 @@ struct MyArticleItemView: View { if let planet = article.planet, let cid = planet.lastPublishedCID, cid.hasPrefix("bafy") { Divider() Button { - let permalink: String = "https://\(cid).eth.sucks\(article.link)" - NSPasteboard.general.clearContents() - NSPasteboard.general.setString(permalink, forType: .string) + if let url = article.permalinkURL { + let permalink: String = url.absoluteString + NSPasteboard.general.clearContents() + NSPasteboard.general.setString(permalink, forType: .string) + } } label: { Text("Copy Permalink") } Button { - let permalink: String = "https://\(cid).eth.sucks\(article.link)" - if let url = URL(string: permalink) { + if let url = article.permalinkURL { NSWorkspace.shared.open(url) } } label: { diff --git a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift index faa2a742..4ee301f3 100644 --- a/Planet/Views/Sidebar/MyPlanetSidebarItem.swift +++ b/Planet/Views/Sidebar/MyPlanetSidebarItem.swift @@ -108,7 +108,7 @@ struct MyPlanetSidebarItem: View { PlanetStore.shared.isEditingPlanetDonationSettings = true } } label: { - Text("Accepts Donation") + Text("Accept Donation") } Button { @@ -442,7 +442,7 @@ struct MyPlanetSidebarItem: View { openiTerm(template) } label: { Image(systemName: "apple.terminal.fill") - Text("Open in iTerm") + Text("Open Template Folder in iTerm") } } diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index 0a6e5998..ad5cd8c4 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2239 +CURRENT_PROJECT_VERSION = 2240