diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 07:53:32 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-23 07:53:32 +0100 |
| commit | 2596140ba29dc959643ae02fb2db4de980ee12e9 (patch) | |
| tree | 54fcc06591020d7ff3d583311170f403a812916d /src/lib/mod.rs | |
| parent | f382b1307ea1020b7dc8fcd9c7fc02f2f612bef7 (diff) | |
fix: remove blossom url trailing slash
when creating announcment with `ngit init`
Diffstat (limited to 'src/lib/mod.rs')
| -rw-r--r-- | src/lib/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
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; | |||
| 8 | 8 | ||
| 9 | use anyhow::{Result, anyhow}; | 9 | use anyhow::{Result, anyhow}; |
| 10 | use directories::ProjectDirs; | 10 | use directories::ProjectDirs; |
| 11 | use nostr_sdk::Url; | ||
| 11 | 12 | ||
| 12 | pub fn get_dirs() -> Result<ProjectDirs> { | 13 | pub fn get_dirs() -> Result<ProjectDirs> { |
| 13 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( | 14 | ProjectDirs::from("", "", "ngit").ok_or(anyhow!( |
| 14 | "should find operating system home directories with rust-directories crate" | 15 | "should find operating system home directories with rust-directories crate" |
| 15 | )) | 16 | )) |
| 16 | } | 17 | } |
| 18 | |||
| 19 | pub trait UrlWithoutSlash { | ||
| 20 | fn as_str_without_trailing_slash(&self) -> &str; | ||
| 21 | fn to_string_without_trailing_slash(&self) -> String; | ||
| 22 | } | ||
| 23 | |||
| 24 | impl UrlWithoutSlash for Url { | ||
| 25 | fn as_str_without_trailing_slash(&self) -> &str { | ||
| 26 | let url_str = self.as_str(); | ||
| 27 | if let Some(without) = url_str.strip_suffix('/') { | ||
| 28 | without | ||
| 29 | } else { | ||
| 30 | url_str | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | fn to_string_without_trailing_slash(&self) -> String { | ||
| 35 | self.as_str_without_trailing_slash().to_string() | ||
| 36 | } | ||
| 37 | } | ||