Add support for a target variable in regular links.

This will initially be used for supporting "post://" links.
main
Tom Alexander 4 months ago
parent cb5d131097
commit 86d4e25aa0
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -11,6 +11,7 @@ use super::RenderObject;
#[serde(tag = "type")]
#[serde(rename = "regular_link")]
pub(crate) struct RenderRegularLink {
target: String,
raw_link: String,
children: Vec<RenderObject>,
post_blank: organic::types::PostBlank,
@ -25,7 +26,13 @@ render!(RenderRegularLink, IRegularLink, original, render_context, {
ret
};
let target = original
.target
.generate_final_target()?
.unwrap_or_else(|| "".to_owned());
Ok(RenderRegularLink {
target: target,
raw_link: original.raw_link.clone(),
children,
post_blank: original.post_blank,

@ -9,6 +9,7 @@ use crate::error::CustomError;
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,
}
@ -25,10 +26,32 @@ intermediate!(
}
ret
};
let raw_link = original.get_raw_link();
let target = LinkTarget::from_string(&raw_link)?;
Ok(IRegularLink {
raw_link: original.get_raw_link().into_owned(),
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> {
Ok(LinkTarget::Raw(input.to_owned()))
}
impl_from_string(input.as_ref())
}
pub(crate) fn generate_final_target(&self) -> Result<Option<String>, CustomError> {
todo!()
}
}

Loading…
Cancel
Save