Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ tempfile = "3.1.0"
fn-error-context = "0.2.0"

# Templating
askama = "0.13.1"
askama = "0.14.0"
walkdir = "2"

# Date and Time utilities
Expand Down
2 changes: 1 addition & 1 deletion src/web/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn with_lang(lang: Option<&str>, code: &str, default: Option<&str>) -> Strin
} else {
log::error!("failed while highlighting code: {err:?}");
}
crate::web::page::templates::filters::escape_html(code)
crate::web::page::templates::filters::escape_html(code, &())
.map(|s| s.to_string())
.unwrap_or_default()
}
Expand Down
29 changes: 21 additions & 8 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ impl TemplateData {
}

pub mod filters {
use askama::Values;
use askama::filters::Safe;
use chrono::{DateTime, Utc};
use std::borrow::Cow;

// Copied from `tera`.
pub fn escape_html(input: &str) -> askama::Result<Cow<'_, str>> {
pub fn escape_html<'a>(input: &'a str, _: &dyn Values) -> askama::Result<Cow<'a, str>> {
if !input.chars().any(|c| "&<>\"'/".contains(c)) {
return Ok(Cow::Borrowed(input));
}
Expand All @@ -115,7 +116,7 @@ pub mod filters {
}

// Copied from `tera`.
pub fn escape_xml(input: &str) -> askama::Result<Cow<'_, str>> {
pub fn escape_xml<'a>(input: &'a str, _: &dyn Values) -> askama::Result<Cow<'a, str>> {
if !input.chars().any(|c| "&<>\"'".contains(c)) {
return Ok(Cow::Borrowed(input));
}
Expand All @@ -135,11 +136,11 @@ pub mod filters {

/// Prettily format a timestamp
// TODO: This can be replaced by chrono
pub fn timeformat(value: &DateTime<Utc>) -> askama::Result<String> {
pub fn timeformat(value: &DateTime<Utc>, _: &dyn Values) -> askama::Result<String> {
Ok(crate::web::duration_to_str(*value))
}

pub fn format_secs(mut value: f32) -> askama::Result<String> {
pub fn format_secs(mut value: f32, _: &dyn Values) -> askama::Result<String> {
const TIMES: &[&str] = &["seconds", "minutes", "hours"];

let mut chosen_time = &TIMES[0];
Expand All @@ -166,6 +167,7 @@ pub mod filters {
#[allow(clippy::unnecessary_wraps)]
pub fn dedent<T: std::fmt::Display, I: Into<Option<i32>>>(
value: T,
_: &dyn Values,
levels: I,
) -> askama::Result<String> {
let string = value.to_string();
Expand Down Expand Up @@ -200,7 +202,11 @@ pub mod filters {
Ok(unindented)
}

pub fn highlight(code: impl std::fmt::Display, lang: &str) -> askama::Result<Safe<String>> {
pub fn highlight(
code: impl std::fmt::Display,
_: &dyn Values,
lang: &str,
) -> askama::Result<Safe<String>> {
let highlighted_code =
crate::web::highlight::with_lang(Some(lang), &code.to_string(), None);
Ok(Safe(format!(
Expand All @@ -209,7 +215,7 @@ pub mod filters {
)))
}

pub fn round(value: &f32, precision: u32) -> askama::Result<String> {
pub fn round(value: &f32, _: &dyn Values, precision: u32) -> askama::Result<String> {
let multiplier = if precision == 0 {
1.0
} else {
Expand All @@ -218,11 +224,18 @@ pub mod filters {
Ok(((multiplier * *value).round() / multiplier).to_string())
}

pub fn split_first<'a>(value: &'a str, pat: &str) -> askama::Result<Option<&'a str>> {
pub fn split_first<'a>(
value: &'a str,
_: &dyn Values,
pat: &str,
) -> askama::Result<Option<&'a str>> {
Ok(value.split(pat).next())
}

pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> askama::Result<Safe<String>> {
pub fn json_encode<T: ?Sized + serde::Serialize>(
value: &T,
_: &dyn Values,
) -> askama::Result<Safe<String>> {
Ok(Safe(
serde_json::to_string(value).expect("`encode_json` failed"),
))
Expand Down
2 changes: 1 addition & 1 deletion templates/releases/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{%- endblock header -%}

{%- block topbar -%}
{% let search_query = search_query %}
{% let search_query = &search_query %}
{%- include "header/topbar.html" -%}
{%- endblock topbar -%}

Expand Down
Loading