server: add link to news posts back to original article
This commit is contained in:
@@ -116,6 +116,29 @@ impl Transformer for InlineStyle {
|
||||
}
|
||||
}
|
||||
|
||||
struct AddOutlink(Option<url::Url>);
|
||||
|
||||
impl Transformer for AddOutlink {
|
||||
fn should_run(&self, _: &str) -> bool {
|
||||
self.0
|
||||
.as_ref()
|
||||
.map(|l| l.scheme().starts_with("http"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
fn transform(&self, html: &str) -> Result<String, TransformError> {
|
||||
if let Some(url) = &self.0 {
|
||||
Ok(format!(
|
||||
r#"
|
||||
{html}
|
||||
<div><a href="{}">View on site</a></div>
|
||||
"#,
|
||||
url
|
||||
))
|
||||
} else {
|
||||
Ok(html.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn linkify_html(text: &str) -> String {
|
||||
let mut finder = LinkFinder::new();
|
||||
let finder = finder.url_must_have_scheme(false).kinds(&[LinkKind::Url]);
|
||||
|
||||
Reference in New Issue
Block a user