mirror of
https://github.com/YGGverse/mb.git
synced 2026-03-31 17:15:28 +00:00
implement clickable links filter
This commit is contained in:
parent
0e897db723
commit
def8f72ece
4 changed files with 26 additions and 3 deletions
|
|
@ -15,6 +15,7 @@ anyhow = "1.0"
|
||||||
chrono = { version = "0.4.41", features = ["serde"] }
|
chrono = { version = "0.4.41", features = ["serde"] }
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
redb = "3.0"
|
redb = "3.0"
|
||||||
|
regex = "1.11"
|
||||||
rocket = "0.5"
|
rocket = "0.5"
|
||||||
rocket_dyn_templates = { version = "0.2", features = ["tera"] }
|
rocket_dyn_templates = { version = "0.2", features = ["tera"] }
|
||||||
url = { version = "2.5", features = ["serde"] }
|
url = { version = "2.5", features = ["serde"] }
|
||||||
|
|
|
||||||
24
src/main.rs
24
src/main.rs
|
|
@ -219,7 +219,29 @@ fn rocket() -> _ {
|
||||||
warn!("Canonical URL option is required for the RSS feed by the specification!") // @TODO
|
warn!("Canonical URL option is required for the RSS feed by the specification!") // @TODO
|
||||||
}
|
}
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.attach(Template::fairing())
|
.attach(Template::custom(|engines| {
|
||||||
|
engines.tera.register_filter("url", {
|
||||||
|
use regex::{Captures, Regex};
|
||||||
|
use rocket_dyn_templates::tera::{Error, Value};
|
||||||
|
Box::new(
|
||||||
|
move |v: &Value,
|
||||||
|
_: &std::collections::HashMap<String, Value>|
|
||||||
|
-> Result<Value, Error> {
|
||||||
|
match v.as_str() {
|
||||||
|
Some(s) => match Regex::new(r"[A-z]+:\/\/(?:[^\s]+|$)") {
|
||||||
|
Ok(r) => Ok(r
|
||||||
|
.replace_all(s, |c: &Captures| {
|
||||||
|
format!("<a href=\"{}\">{}</a>", &c[0], &c[0])
|
||||||
|
})
|
||||||
|
.into()),
|
||||||
|
Err(e) => Err(Error::msg(e)),
|
||||||
|
},
|
||||||
|
None => Err(Error::msg("Expected a string")),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}))
|
||||||
.configure(rocket::Config {
|
.configure(rocket::Config {
|
||||||
port: config.port,
|
port: config.port,
|
||||||
address: config.host,
|
address: config.host,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div>
|
<div>
|
||||||
<a name="{{ post.id }}"></a>
|
<a name="{{ post.id }}"></a>
|
||||||
<p>{{ post.message | linebreaksbr | safe }}</p>
|
<p>{{ post.message | url | linebreaksbr | safe }}</p>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ post.href.post }}" title="Created">{{ post.time }}</a></li>
|
<li><a href="{{ post.href.post }}" title="Created">{{ post.time }}</a></li>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div>
|
<div>
|
||||||
<a name="{{ post.id }}"></a>
|
<a name="{{ post.id }}"></a>
|
||||||
<p>{{ post.message | linebreaksbr | safe }}</p>
|
<p>{{ post.message | url | linebreaksbr | safe }}</p>
|
||||||
<div>
|
<div>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ post.href.post }}" title="Created">{{ post.time }}</a></li>
|
<li><a href="{{ post.href.post }}" title="Created">{{ post.time }}</a></li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue