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
22 changes: 4 additions & 18 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,6 @@ pub mod filters {
)))
}

pub fn slugify<T: AsRef<str>>(code: T) -> rinja::Result<String> {
Ok(slug::slugify(code.as_ref()))
}

pub fn round(value: &f32, precision: u32) -> rinja::Result<String> {
let multiplier = if precision == 0 {
1.0
Expand All @@ -234,24 +230,14 @@ pub mod filters {
Ok(((multiplier * *value).round() / multiplier).to_string())
}

pub fn date(value: &DateTime<Utc>, format: &str) -> rinja::Result<String> {
Ok(format!("{}", value.format(format)))
}

pub fn opt_date(value: &Option<DateTime<Utc>>, format: &str) -> rinja::Result<String> {
if let Some(value) = value {
date(value, format)
} else {
Ok(String::new())
}
}

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

pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> rinja::Result<String> {
Ok(serde_json::to_string(value).expect("`encode_json` failed"))
pub fn json_encode<T: ?Sized + serde::Serialize>(value: &T) -> rinja::Result<Safe<String>> {
Ok(Safe(
serde_json::to_string(value).expect("`encode_json` failed"),
))
}

pub fn rest_menu_url(current_target: &str, inner_path: &str) -> rinja::Result<String> {
Expand Down
11 changes: 6 additions & 5 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<meta name="generator" content="docs.rs {{ crate::BUILD_VERSION }}">
{%- block meta -%}{%- endblock meta -%}

{# Docs.rs styles #}
<link rel="stylesheet" href="/-/static/vendored.css?{{ crate::BUILD_VERSION|slugify }}" media="all" />
<link rel="stylesheet" href="/-/static/style.css?{{ crate::BUILD_VERSION|slugify }}" media="all" />
{#- Docs.rs styles -#}
{%- set build_slug = slug::slugify(crate::BUILD_VERSION) -%}
<link rel="stylesheet" href="/-/static/vendored.css?{{ build_slug }}" media="all" />
<link rel="stylesheet" href="/-/static/style.css?{{ build_slug }}" media="all" />

<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />

Expand All @@ -18,8 +19,8 @@
<script nonce="{{ csp_nonce }}">{%- include "theme.js" -%}</script>
{%- block css -%}{%- endblock css -%}

<script defer type="text/javascript" nonce="{{ csp_nonce }}" src="/-/static/menu.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script defer type="text/javascript" nonce="{{ csp_nonce }}" src="/-/static/index.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script defer type="text/javascript" nonce="{{ csp_nonce }}" src="/-/static/menu.js?{{ build_slug }}"></script>
<script defer type="text/javascript" nonce="{{ csp_nonce }}" src="/-/static/index.js?{{ build_slug }}"></script>
</head>

<body class="{% block body_classes %}{% endblock body_classes %}">
Expand Down
4 changes: 2 additions & 2 deletions templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1 class="brand">{{ "cubes"|fas(false, false, "") }} Docs.rs</h1>

{%- if let Some(build_time) = release.build_time -%}
<div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date"
title="{{ build_time|date("%FT%TZ") }}">
title="{{ build_time.format("%FT%TZ") }}">
{{ build_time|timeformat }}
</div>
{%- endif -%}
Expand All @@ -76,5 +76,5 @@ <h1 class="brand">{{ "cubes"|fas(false, false, "") }} Docs.rs</h1>
{%- endblock body -%}

{%- block javascript -%}
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/keyboard.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/keyboard.js?{{ build_slug }}"></script>
{%- endblock javascript -%}
2 changes: 1 addition & 1 deletion templates/crate/build_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="container">
<div class="recent-releases-container">
<div class="release">
<strong>Build #{{ build_details.id }} {%- if let Some(build_time) = build_details.build_time %} {{ build_time|date("%+") }}{% endif %}</strong>
<strong>Build #{{ build_details.id }} {%- if let Some(build_time) = build_details.build_time %} {{ build_time.format("%+") }}{% endif %}</strong>
</div>

<ul>
Expand Down
2 changes: 1 addition & 1 deletion templates/crate/source.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@

{%- block javascript -%}
{% if file_content.is_some() %}
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/source.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/source.js?{{ slug::slugify(crate::BUILD_VERSION) }}"></script>
{% endif %}
{%- endblock javascript -%}
10 changes: 8 additions & 2 deletions templates/releases/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
<id>urn:docs-rs:{{ crate::BUILD_VERSION }}</id>
<updated>
{%- if let Some(first_release) = recent_releases.get(0) -%}
{{ first_release.build_time|opt_date("%+") }}
{%- if let Some(build_time) = first_release.build_time -%}
{{ build_time.format("%+") }}
{%- endif -%}
{%- endif -%}
</updated>

Expand All @@ -28,7 +30,11 @@

<link href="{{ link|safe }}" />
<id>urn:docs-rs:{{ release.name }}:{{ release.version }}</id>
<updated>{{ release.build_time|opt_date("%+") }}</updated>
<updated>
{% if let Some(build_time) = release.build_time -%}
{{ build_time.format("%+") }}
{%- endif -%}
</updated>

<summary>
{%- if let Some(description) = release.description -%}
Expand Down
4 changes: 2 additions & 2 deletions templates/releases/releases.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
</div>
{%- elif let Some(build_time) = release.build_time -%}
<div class="pure-u-1 pure-u-sm-4-24 pure-u-md-3-24 date"
title="{{ build_time|date("%FT%TZ") }}">
title="{{ build_time.format("%FT%TZ") }}">
{{ build_time|timeformat }}
</div>
{%- else -%}
Expand Down Expand Up @@ -102,5 +102,5 @@
{%- endblock body -%}

{%- block javascript -%}
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/keyboard.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script nonce="{{ csp_nonce }}" type="text/javascript" src="/-/static/keyboard.js?{{ build_slug }}"></script>
{%- endblock javascript -%}
5 changes: 3 additions & 2 deletions templates/rustdoc/body.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script async src="/-/static/menu.js?{{ crate::BUILD_VERSION|slugify }}"></script>
<script async src="/-/static/index.js?{{ crate::BUILD_VERSION|slugify }}"></script>
{%- set build_slug = slug::slugify(crate::BUILD_VERSION) -%}
<script async src="/-/static/menu.js?{{ build_slug }}"></script>
<script async src="/-/static/index.js?{{ build_slug }}"></script>
{# see comment in ../storage-change-detection.html for details #}
<iframe src="/-/storage-change-detection.html" width="0" height="0" style="display: none"></iframe>
2 changes: 1 addition & 1 deletion templates/rustdoc/head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- import "macros.html" as macros -%}
<link rel="stylesheet" href="/-/static/{{rustdoc_css_file.as_ref().unwrap()}}?{{ crate::BUILD_VERSION|slugify }}" media="all" />
<link rel="stylesheet" href="/-/static/{{rustdoc_css_file.as_ref().unwrap()}}?{% if build_slug is defined %}{{ build_slug }}{% else %}{{ slug::slugify(crate::BUILD_VERSION) }}{% endif %}" media="all" />

<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />

Expand Down
4 changes: 2 additions & 2 deletions templates/rustdoc/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
{# the only text that needs escaping in a <script> is `</`, none of the
values below can include that sequence #}
{
"name": {{ metadata.name|json_encode|safe }},
"version": {{ metadata.version|json_encode|safe }}
"name": {{ metadata.name|json_encode }},
"version": {{ metadata.version|json_encode }}
}
</script>
{%- if krate is defined -%}
Expand Down
3 changes: 1 addition & 2 deletions templates/rustdoc/vendored.html
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<link rel="stylesheet" href="/-/static/vendored.css?{{ crate::BUILD_VERSION|slugify }}" media="all" />

<link rel="stylesheet" href="/-/static/vendored.css?{{ slug::slugify(crate::BUILD_VERSION) }}" media="all" />
Loading