diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/mod.rs | 21 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 5 |
2 files changed, 25 insertions, 1 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 | } | ||
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}; | |||
| 18 | #[cfg(not(test))] | 18 | #[cfg(not(test))] |
| 19 | use crate::client::Client; | 19 | use crate::client::Client; |
| 20 | use crate::{ | 20 | use crate::{ |
| 21 | UrlWithoutSlash, | ||
| 21 | cli_interactor::{ | 22 | cli_interactor::{ |
| 22 | Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, | 23 | Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, |
| 23 | }, | 24 | }, |
| @@ -204,7 +205,9 @@ impl RepoRef { | |||
| 204 | } else { | 205 | } else { |
| 205 | vec![Tag::custom( | 206 | vec![Tag::custom( |
| 206 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("blossoms")), | 207 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("blossoms")), |
| 207 | self.blossoms.iter().map(|r| r.to_string()), | 208 | self.blossoms |
| 209 | .iter() | ||
| 210 | .map(|r| r.to_string_without_trailing_slash()), | ||
| 208 | )] | 211 | )] |
| 209 | }, | 212 | }, |
| 210 | // code languages and hashtags | 213 | // code languages and hashtags |