Generate Post link when the protocol is post.
This commit is contained in:
parent
93e0a2fe98
commit
6a086d57de
@ -41,14 +41,24 @@ intermediate!(
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) enum LinkTarget {
|
||||
Raw(String),
|
||||
Post { post_id: String },
|
||||
Post { post_id: Option<String> },
|
||||
}
|
||||
|
||||
impl LinkTarget {
|
||||
pub(crate) fn from_string<S: AsRef<str>>(input: S) -> Result<LinkTarget, CustomError> {
|
||||
fn impl_from_string(input: &str) -> Result<LinkTarget, CustomError> {
|
||||
let parsed = Url::parse(input)?;
|
||||
Ok(LinkTarget::Raw(input.to_owned()))
|
||||
match parsed.scheme() {
|
||||
"post" => {
|
||||
let post_id = parsed
|
||||
.path_segments()
|
||||
.ok_or_else(|| "cannot be base")?
|
||||
.next()
|
||||
.map(str::to_owned);
|
||||
Ok(LinkTarget::Post { post_id })
|
||||
}
|
||||
_ => Ok(LinkTarget::Raw(input.to_owned())),
|
||||
}
|
||||
}
|
||||
impl_from_string(input.as_ref())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user