add support for %NAME% and url_string (permalinks)

This commit is contained in:
Trevor Bentley
2023-01-17 00:24:49 +01:00
parent f787ec91b3
commit 48b6dd056a
5 changed files with 45 additions and 14 deletions
+10
View File
@@ -21,6 +21,7 @@
* along with Itsy-Gitsy. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::git::GitFile;
use crate::util::{sanitize_path_component, urlify_path};
use chrono::{naive::NaiveDateTime, offset::FixedOffset, DateTime};
use serde::Serialize;
use std::collections::HashMap;
@@ -116,6 +117,15 @@ impl Filter for MaskFilter {
}
}
pub struct UrlStringFilter;
impl Filter for UrlStringFilter {
fn filter(&self, value: &Value, _args: &HashMap<String, Value>) -> Result<Value, tera::Error> {
let v: String = try_get_value!("url_string", "value", String, value);
let sanitized = sanitize_path_component(&urlify_path(&v));
Ok(to_value(sanitize_path_component(&sanitized)).unwrap())
}
}
pub struct TsDateFn;
impl Function for TsDateFn {
fn call(&self, args: &HashMap<String, Value>) -> Result<Value, tera::Error> {