60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
use organic::types::StandardProperties;
|
|
use url::Url;
|
|
|
|
use super::macros::intermediate;
|
|
|
|
use super::IObject;
|
|
use crate::error::CustomError;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct IRegularLink {
|
|
pub(crate) raw_link: String,
|
|
pub(crate) children: Vec<IObject>,
|
|
pub(crate) target: LinkTarget,
|
|
pub(crate) post_blank: organic::types::PostBlank,
|
|
}
|
|
|
|
intermediate!(
|
|
IRegularLink,
|
|
&'orig organic::types::RegularLink<'parse>,
|
|
original,
|
|
intermediate_context,
|
|
{
|
|
let children = {
|
|
let mut ret = Vec::new();
|
|
for obj in original.children.iter() {
|
|
ret.push(IObject::new(intermediate_context.clone(), obj).await?);
|
|
}
|
|
ret
|
|
};
|
|
let raw_link = original.get_raw_link();
|
|
let target = LinkTarget::from_string(&raw_link)?;
|
|
Ok(IRegularLink {
|
|
raw_link: raw_link.into_owned(),
|
|
children,
|
|
target,
|
|
post_blank: original.get_post_blank(),
|
|
})
|
|
}
|
|
);
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) enum LinkTarget {
|
|
Raw(String),
|
|
Post { post_id: 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()))
|
|
}
|
|
impl_from_string(input.as_ref())
|
|
}
|
|
|
|
pub(crate) fn generate_final_target(&self) -> Result<Option<String>, CustomError> {
|
|
todo!()
|
|
}
|
|
}
|