diff --git a/Cargo.lock b/Cargo.lock index d72a58b..73cfb5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1184,6 +1184,7 @@ dependencies = [ "thiserror", "tokio", "url", + "urlencoding", ] [[package]] @@ -2810,6 +2811,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index e475380..c305191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ tokio = { version = "1.20.1", features = ["macros"] } # To extract the base URI url = "2.2.2" +urlencoding = "2.1.3" # CLI clap = { version = "4.4.12", features = ["derive", "env"] } diff --git a/src/gooseberry/knowledge_base.rs b/src/gooseberry/knowledge_base.rs index 613ace7..4c2a617 100644 --- a/src/gooseberry/knowledge_base.rs +++ b/src/gooseberry/knowledge_base.rs @@ -88,6 +88,7 @@ pub(crate) fn format_date>( } handlebars_helper!(date_format: |format: str, date: Json| format_date(format, date).map_err(|e| RenderError::from_error("serde_json", e))?); +handlebars_helper!(url_encode: |s: str| {urlencoding::encode(s).to_string()}); pub(crate) struct Templates<'a> { pub(crate) annotation_template: &'a str, @@ -110,6 +111,7 @@ pub(crate) fn get_handlebars(templates: Templates) -> color_eyre::Result