From 2596140ba29dc959643ae02fb2db4de980ee12e9 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 23 May 2025 07:53:32 +0100 Subject: fix: remove blossom url trailing slash when creating announcment with `ngit init` --- src/lib/mod.rs | 21 +++++++++++++++++++++ src/lib/repo_ref.rs | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 2072a80..7c7bd6a 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -8,9 +8,30 @@ pub mod repo_state; use anyhow::{Result, anyhow}; use directories::ProjectDirs; +use nostr_sdk::Url; pub fn get_dirs() -> Result { ProjectDirs::from("", "", "ngit").ok_or(anyhow!( "should find operating system home directories with rust-directories crate" )) } + +pub trait UrlWithoutSlash { + fn as_str_without_trailing_slash(&self) -> &str; + fn to_string_without_trailing_slash(&self) -> String; +} + +impl UrlWithoutSlash for Url { + fn as_str_without_trailing_slash(&self) -> &str { + let url_str = self.as_str(); + if let Some(without) = url_str.strip_suffix('/') { + without + } else { + url_str + } + } + + fn to_string_without_trailing_slash(&self) -> String { + self.as_str_without_trailing_slash().to_string() + } +} diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 1a0fe85..df1427a 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -18,6 +18,7 @@ use serde::{Deserialize, Serialize}; #[cfg(not(test))] use crate::client::Client; use crate::{ + UrlWithoutSlash, cli_interactor::{ Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, }, @@ -204,7 +205,9 @@ impl RepoRef { } else { vec![Tag::custom( nostr::TagKind::Custom(std::borrow::Cow::Borrowed("blossoms")), - self.blossoms.iter().map(|r| r.to_string()), + self.blossoms + .iter() + .map(|r| r.to_string_without_trailing_slash()), )] }, // code languages and hashtags -- cgit v1.2.3