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 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/lib/mod.rs') 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() + } +} -- cgit v1.2.3