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
26 changes: 18 additions & 8 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 @@ -22,7 +22,7 @@ exclude = [

[workspace.dependencies]
anyhow = { version = "1.0.42", features = ["backtrace"]}
askama = "0.14.0"
askama = "0.15.0"
async-stream = "0.3.5"
axum-extra = { version = "0.12.0", features = ["typed-header", "routing", "middleware"] }
bincode = "~2" # bincode is unmaintained, and 3.0 is just a breaking notification
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_inner(code)
.map(|s| s.to_string())
.unwrap_or_default()
}
Expand Down
28 changes: 17 additions & 11 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ pub mod filters {
use askama::filters::Safe;
use chrono::{DateTime, Utc};
use std::borrow::Cow;
use std::fmt::Display;

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

// Copied from `tera`.
pub fn escape_xml<'a>(input: &'a str, _: &dyn Values) -> askama::Result<Cow<'a, str>> {
#[askama::filter_fn]
pub fn escape_html(input: &str, _: &dyn Values) -> askama::Result<impl Display> {
escape_html_inner(input)
}

// Copied from `tera`.
#[askama::filter_fn]
pub fn escape_xml(input: &str, _: &dyn Values) -> askama::Result<impl Display> {
if !input.chars().any(|c| "&<>\"'".contains(c)) {
return Ok(Cow::Borrowed(input));
}
Expand All @@ -138,15 +145,18 @@ pub mod filters {

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

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

let mut chosen_time = &TIMES[0];

let mut value = value;
for time in &TIMES[1..] {
if value / 60.0 >= 1.0 {
chosen_time = time;
Expand All @@ -167,6 +177,7 @@ pub mod filters {

/// Dedent a string by removing all leading whitespace
#[allow(clippy::unnecessary_wraps)]
#[askama::filter_fn]
pub fn dedent<T: std::fmt::Display, I: Into<Option<i32>>>(
value: T,
_: &dyn Values,
Expand Down Expand Up @@ -204,6 +215,7 @@ pub mod filters {
Ok(unindented)
}

#[askama::filter_fn]
pub fn highlight(
code: impl std::fmt::Display,
_: &dyn Values,
Expand All @@ -214,6 +226,7 @@ pub mod filters {
Ok(Safe(format!("<pre><code>{highlighted_code}</code></pre>")))
}

#[askama::filter_fn]
pub fn round(value: &f32, _: &dyn Values, precision: u32) -> askama::Result<String> {
let multiplier = if precision == 0 {
1.0
Expand All @@ -223,14 +236,7 @@ pub mod filters {
Ok(((multiplier * *value).round() / multiplier).to_string())
}

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

#[askama::filter_fn]
pub fn json_encode<T: ?Sized + serde::Serialize>(
value: &T,
_: &dyn Values,
Expand Down
2 changes: 1 addition & 1 deletion templates/core/about/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ <h4 id="hitting-resource-limits"> <a href="#hitting-resource-limits">Hitting res
All the builds are executed inside a sandbox with limited resources. The current limits are:
</p>

{% call macros::crate_limits(limits=limits) %}
{% call macros::crate_limits(limits=limits) %}{% endcall %}

<p>
If your build fails because it hit one of these limits, please
Expand Down
2 changes: 1 addition & 1 deletion templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1 class="brand">{{ crate::icons::IconCubes.render_solid(false, false, "") }} D
<ul>
{%- for release in recent_releases -%}
{%- set release_params = release.rustdoc_params() -%}
{% set release_url %}
{% decl release_url %}
{%- if release.rustdoc_status -%}
{%- set release_url = release_params.rustdoc_url() -%}
{%- else -%}
Expand Down
4 changes: 2 additions & 2 deletions templates/crate/build_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}{% endcall %}
{%- endblock title -%}

{%- block body_classes -%}
Expand All @@ -14,7 +14,7 @@
{%- endblock topbar -%}

{%- block header -%}
{% call navigation::package_navigation(metadata=metadata, active_tab="builds") %}
{% call navigation::package_navigation(metadata=metadata, active_tab="builds") %}{% endcall %}
{%- endblock header -%}

{%- block body -%}
Expand Down
6 changes: 3 additions & 3 deletions templates/crate/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}{% endcall %}
{%- endblock title -%}

{%- block meta -%}
Expand All @@ -18,7 +18,7 @@
{%- endblock topbar -%}

{%- block header -%}
{% call navigation::package_navigation(metadata=metadata, active_tab="builds") %}
{% call navigation::package_navigation(metadata=metadata, active_tab="builds") %}{% endcall %}
{%- endblock header -%}

{%- block body -%}
Expand Down Expand Up @@ -100,7 +100,7 @@ <h4>{{ metadata.name }}'s sandbox limits</h4>
resources. The limits for this crate are the following:
</p>

{% call macros::crate_limits(limits=limits) %}
{% call macros::crate_limits(limits=limits) %}{% endcall %}

<p>
If a build fails because it hit one of those limits please
Expand Down
8 changes: 4 additions & 4 deletions templates/crate/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
{% call macros::doc_title(name=name, version=version) %}
{% call macros::doc_title(name=name, version=version) %}{% endcall %}
{%- endblock title -%}

{%- block meta -%}
Expand All @@ -15,7 +15,7 @@

{%- block header -%}
{# Set the active tab to the `crate` tab #}
{% call navigation::package_navigation(metadata=metadata, active_tab="crate") %}
{% call navigation::package_navigation(metadata=metadata, active_tab="crate") %}{% endcall %}
{%- endblock header -%}

{%- block body -%}
Expand Down Expand Up @@ -112,7 +112,7 @@
<div class="pure-menu pure-menu-scrollable sub-menu">
<ul class="pure-menu-list">
{# List all dependencies that the current release has #}
{% call macros::dependencies_list(dependencies=dependencies, use_crate_details = true, if_empty="&mdash;") %}
{% call macros::dependencies_list(dependencies=dependencies, use_crate_details = true, if_empty="&mdash;") %}{% endcall %}
</ul>
</div>
</li>
Expand All @@ -122,7 +122,7 @@
<div class="pure-menu pure-menu-scrollable sub-menu">
<ul class="pure-menu-list">
{# Display all releases of this crate #}
{% call macros::releases_list(params=params, releases=releases, use_target_redirect = false, retain_fragment = false) %}
{% call macros::releases_list(params=params, releases=releases, use_target_redirect = false, retain_fragment = false) %}{% endcall %}
</ul>
</div>
</li>
Expand Down
4 changes: 2 additions & 2 deletions templates/crate/features.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}{% endcall %}
{%- endblock title -%}

{%- block meta -%}
Expand All @@ -14,7 +14,7 @@
{%- endblock topbar -%}

{%- block header -%}
{% call navigation::package_navigation(metadata=metadata, active_tab="features") %}
{% call navigation::package_navigation(metadata=metadata, active_tab="features") %}{% endcall %}
{%- endblock header -%}

{%- block body -%}
Expand Down
8 changes: 4 additions & 4 deletions templates/crate/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- import "header/package_navigation.html" as navigation -%}

{%- block title -%}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}
{% call macros::doc_title(name=metadata.name, version=metadata.version) %}{% endcall %}
{%- endblock title -%}

{%- block topbar -%}
Expand All @@ -11,7 +11,7 @@

{%- block header -%}
{# Set the active tab to the `source` tab #}
{% call navigation::package_navigation(metadata=metadata, active_tab="source") %}
{% call navigation::package_navigation(metadata=metadata, active_tab="source") %}{% endcall %}
{%- endblock header -%}

{%- block body_classes -%}
Expand Down Expand Up @@ -84,7 +84,7 @@
#}

{# Text files or files which mime starts with `text` #}
{%- elif file.mime == "text/plain" || file.mime|split_first("/") == Some("text") -%}
{%- elif file.mime == "text/plain" || file.mime.split('/').next() == Some("text") -%}
{{ crate::icons::IconFileLines.render_regular(false, false, "") }}

{# Binary files and any unrecognized types #}
Expand Down Expand Up @@ -113,7 +113,7 @@

{# If the file has content, then display it in a codeblock #}
{%- if let Some(file_content) = file_content -%}
{% set file_name %}
{% decl file_name %}
{% if let Some(file) = file %}
{% set file_name = file.name.as_str() %}
{% else %}
Expand Down
Loading
Loading