Skip to content

Commit ca53c37

Browse files
committed
Fixed-width and icon escaping
1 parent 1b8462f commit ca53c37

File tree

11 files changed

+92
-66
lines changed

11 files changed

+92
-66
lines changed

src/web/page/templates.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,39 @@ impl fmt::Display for IconType {
274274

275275
impl tera::Filter for IconType {
276276
fn filter(&self, value: &Value, args: &HashMap<String, Value>) -> TeraResult<Value> {
277+
let mut aria_hidden = true;
278+
let class = tera::escape_html(value.as_str().expect("Icons only take strings"));
279+
let fixed_width = if args.get("fw").and_then(|fw| fw.as_bool()).unwrap_or(false) {
280+
" fa-fw"
281+
} else {
282+
""
283+
};
284+
let aria_label = args
285+
.get("aria-label")
286+
.and_then(|l| l.as_str())
287+
.map(|label| {
288+
aria_hidden = false;
289+
format!(r#" aria-label="{}""#, tera::escape_html(label))
290+
})
291+
.unwrap_or_default();
292+
let id = args
293+
.get("id")
294+
.and_then(|l| l.as_str())
295+
.map(|id| format!(r#" id="{}""#, tera::escape_html(id)))
296+
.unwrap_or_default();
297+
aria_hidden = args
298+
.get("aria-hidden")
299+
.and_then(|l| l.as_bool())
300+
.unwrap_or(aria_hidden);
301+
277302
let icon = format!(
278-
r#"<span class="{} fa-{}" aria-hidden="true" {}></span>"#,
279-
self,
280-
value.as_str().expect("Icons only take strings"),
281-
args.get("extra")
282-
.and_then(Value::as_str)
283-
.unwrap_or_default(),
303+
r#"<span aria-hidden="{aria_hidden}" class="{icon_class} fa-{fa_class}{fw}"{aria_label}{id}></span>"#,
304+
aria_hidden = aria_hidden,
305+
icon_class = self,
306+
fa_class = class,
307+
fw = fixed_width,
308+
aria_label = aria_label,
309+
id = id,
284310
);
285311

286312
Ok(Value::String(icon))

templates/about-base.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
<h3 id="crate-title">Docs.rs documentation</h3>
77
<div class="pure-menu pure-menu-horizontal">
88
<ul class="pure-menu-list">
9-
{% set text = "info-circle" | fas %}
9+
{% set text = "info-circle" | fas(fw=true) %}
1010
{% set text = text ~ ' <span class="title">About</span>' %}
1111
{{ macros::active_link(expected="index", href="/about", text=text) }}
1212

13-
{% set text = "fonticons" | fab%}
13+
{% set text = "fonticons" | fab(fw=true) %}
1414
{% set text = text ~ ' <span class="title">Badges</span>' %}
1515
{{ macros::active_link(expected="badges", href="/about/badges", text=text) }}
1616

17-
{% set text = "cogs" | fas %}
17+
{% set text = "cogs" | fas(fw=true) %}
1818
{% set text = text ~ ' <span class="title">Builds</span>' %}
1919
{{ macros::active_link(expected="builds", href="/about/builds", text=text) }}
2020

21-
{% set text = "table" | fas %}
21+
{% set text = "table" | fas(fw=true) %}
2222
{% set text = text ~ ' <span class="title">Metadata</span>' %}
2323
{{ macros::active_link(expected="metadata", href="/about/metadata", text=text) }}
2424

25-
{% set text = "road" | fas %}
25+
{% set text = "road" | fas(fw=true) %}
2626
{% set text = text ~ ' <span class="title">Shorthand URLs</span>' %}
2727
{{ macros::active_link(expected="redirections", href="/about/redirections", text=text) }}
2828
</ul>

templates/core/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{%- block body -%}
66
<div class="container landing">
7-
<h1 class="brand">{{ "cubes" | fas }} Docs.rs</h1>
7+
<h1 class="brand">{{ "cubes" | fas(fw=true) }} Docs.rs</h1>
88

99
<form action="/releases/search" method="GET" class="landing-search-form">
1010
<div>

templates/crate/details.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{%- if details.homepage_url -%}
4040
<li class="pure-menu-item">
4141
<a href="{{ details.homepage_url }}" class="pure-menu-link">
42-
{{ "home" | fas }} Homepage
42+
{{ "home" | fas(fw=true) }} Homepage
4343
</a>
4444
</li>
4545
{%- endif -%}
@@ -48,7 +48,7 @@
4848
{%- if details.documentation_url -%}
4949
<li class="pure-menu-item">
5050
<a href="{{ details.documentation_url }}" title="Canonical documentation" class="pure-menu-link">
51-
{{ "file-alt" | far }} Documentation
51+
{{ "file-alt" | far(fw=true) }} Documentation
5252
</a>
5353
</li>
5454
{%- endif -%}
@@ -60,14 +60,14 @@
6060
{# If the repo link is for github, show some github stats #}
6161
{# TODO: add support for hosts besides github (#35) #}
6262
{%- if details.github -%}
63-
{{ "github" | fab }}
64-
{{ "star" | fas }} {{ details.github_stars }}
65-
{{ "code-branch" | fas }} {{ details.github_forks }}
66-
{{ "exclamation-circle" | fas }} {{ details.github_issues }}
63+
{{ "github" | fab(fw=true) }}
64+
{{ "star" | fas(fw=true) }} {{ details.github_stars }}
65+
{{ "code-branch" | fas(fw=true) }} {{ details.github_forks }}
66+
{{ "exclamation-circle" | fas(fw=true) }} {{ details.github_issues }}
6767

6868
{# If the repo link is unknown, just show a normal link #}
6969
{%- else -%}
70-
{{ "code-branch" | fas }} Repository
70+
{{ "code-branch" | fas(fw=true) }} Repository
7171
{%- endif -%}
7272
</a>
7373
</li>
@@ -77,7 +77,7 @@
7777
<li class="pure-menu-item">
7878
<a href="https://crates.io/crates/{{ details.name }}" class="pure-menu-link"
7979
title="See {{ details.name }} on crates.io">
80-
{{ "cube" | fas }} Crates.io
80+
{{ "cube" | fas(fw=true) }} Crates.io
8181
</a>
8282
</li>
8383

templates/crate/source.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{# If this isn't the root folder, show a 'back' button #}
2020
{%- if show_parent_link -%}
2121
<li class="pure-menu-item">
22-
<a href="../" class="pure-menu-link">{{ "folder-open" | far }} ..</a>
22+
<a href="../" class="pure-menu-link">{{ "folder-open" | far(fw=true) }} ..</a>
2323
</li>
2424
{%- endif -%}
2525

@@ -32,23 +32,23 @@
3232
<a href="./{{ file.name }}{% if file.mime == 'dir' %}/{% endif %}" class="pure-menu-link">
3333
{# Directories #}
3434
{%- if file.mime == "dir" -%}
35-
{{ "folder-open" | far }}
35+
{{ "folder-open" | far(fw=true) }}
3636

3737
{# Rust files #}
3838
{%- elif file.mime == "text/rust" -%}
39-
{{ "rust" | fab }}
39+
{{ "rust" | fab(fw=true) }}
4040

4141
{# Cargo.lock #}
4242
{%- elif file.mime == "text/plain" and file.name == "Cargo.lock" -%}
43-
{{ "lock" | fas }}
43+
{{ "lock" | fas(fw=true) }}
4444

4545
{# Markdown files #}
4646
{% elif file.mime == "text/markdown" %}
47-
{{ "markdown" | fab }}
47+
{{ "markdown" | fab(fw=true) }}
4848

4949
{# .gitignore #}
5050
{% elif file.mime == "text/plain" and file.name == ".gitignore" %}
51-
{{ "git-alt" | fab }}
51+
{{ "git-alt" | fab(fw=true) }}
5252

5353
{#
5454
More ideas
@@ -70,11 +70,11 @@
7070

7171
{# Text files or files which mime starts with `text` #}
7272
{%- elif file.mime == "text/plain" or file.mime | split(pat="/") | first == "text" -%}
73-
{{ "file-alt" | far }}
73+
{{ "file-alt" | far(fw=true) }}
7474

7575
{# Binary files and any unrecognized types #}
7676
{% else -%}
77-
{{ "file-archive" | far }}
77+
{{ "file-archive" | far(fw=true) }}
7878
{%- endif -%}
7979

8080
{{ file.name }}

templates/header/global_alert.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{%- if global_alert -%}
66
<li class="pure-menu-item">
77
<a href="{{ global_alert.url | safe }}" class="pure-menu-link {{ global_alert.css_class }}">
8-
<i class="{{ global_alert.fa_icon | fas }}"></i>
8+
<i class="{{ global_alert.fa_icon | fas(fw=true) }}"></i>
99
{{ global_alert.text }}
1010
</a>
1111
</li>

templates/header/package_navigation.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h1 id="crate-title">
2121
{{ title }}
2222
{%- else -%}
2323
{{ metadata.name }} {{ metadata.version }}
24-
{{ "copy" | far(extra='id="clipboard" aria-label="Copy crate name and version information"') | safe }}
24+
{{ "copy" | far(id="clipboard", aria-label="Copy crate name and version information", fa=true) }}
2525
{%- endif -%}
2626
</h1>
2727

@@ -61,7 +61,7 @@ <h1 id="crate-title">
6161
<li class="pure-menu-item">
6262
{# The docs tab redirects to the docs, so the tab will never be selected and seen #}
6363
<a href="/{{ crate_path | safe }}/{{ metadata.target_name }}/" class="pure-menu-link">
64-
{{ "book" | fas }}
64+
{{ "book" | fas(fw=true) }}
6565
<span class="title"> Documentation</span>
6666
</a>
6767
</li>
@@ -70,7 +70,7 @@ <h1 id="crate-title">
7070
{# The crate information tab #}
7171
<li class="pure-menu-item"><a href="/crate/{{ crate_path | safe }}"
7272
class="pure-menu-link{% if active_tab == 'crate' %} pure-menu-active{% endif %}">
73-
{{ "cube" | fas }}
73+
{{ "cube" | fas(fw=true) }}
7474
<span class="title"> Crate</span>
7575
</a>
7676
</li>
@@ -79,7 +79,7 @@ <h1 id="crate-title">
7979
<li class="pure-menu-item">
8080
<a href="/crate/{{ crate_path | safe }}/source/"
8181
class="pure-menu-link{% if active_tab == 'source' %} pure-menu-active{% endif %}">
82-
{{ "folder-open" | far }}
82+
{{ "folder-open" | far(fw=true) }}
8383
<span class="title"> Source</span>
8484
</a>
8585
</li>

templates/header/topbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{# The search bar #}
1111
<div id="search-input-nav">
1212
<label for="nav-search">
13-
{{ "search" | fas }}
13+
{{ "search" | fas(fw=true) }}
1414
</label>
1515

1616
{# If there is a search query, put it in the search bar #}
@@ -20,7 +20,7 @@
2020

2121
{# The top-left logo and name #}
2222
<a href="/" class="pure-menu-heading pure-menu-link" aria-label="Docs.rs">
23-
{{ "cubes" | fas }} Docs.rs
23+
{{ "cubes" | fas(fw=true) }} Docs.rs
2424
</a>
2525

2626
<ul class="pure-menu-list">

templates/macros.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,26 @@
126126
{# If the release isn't a library, then display that warning #}
127127
{% if not release.is_library -%}
128128
<a href="{{ release_url | safe }}" class="pure-menu-link warn" title="{{ release_name }} is not a library">
129-
{{ "exclamation-triangle" | fas }} {{ release.version }}
129+
{{ "exclamation-triangle" | fas(fw=true) }} {{ release.version }}
130130
</a>
131131

132132
{# If the release has been yanked and failed to build, display a warning #}
133133
{%- elif release.yanked and release.build_status -%}
134134
<a href="{{ release_url | safe }}" class="pure-menu-link warn" title="{{ release_name }} is yanked">
135-
{{ "exclamation-triangle" | fas }} {{ release.version }}
135+
{{ "exclamation-triangle" | fas(fw=true) }} {{ release.version }}
136136
</a>
137137

138138
{# If the release has been yanked and failed to build, display a warning #}
139139
{%- elif release.yanked and not release.build_status -%}
140140
<a href="{{ release_url | safe }}" class="pure-menu-link warn"
141141
title="{{ release_name }} is yanked and docs.rs failed to build it">
142-
{{ "exclamation-triangle" | fas }} {{ release.version }}
142+
{{ "exclamation-triangle" | fas(fw=true) }} {{ release.version }}
143143
</a>
144144

145145
{# If the release failed to build, display a warning #}
146146
{%- elif not release.build_status -%}
147147
<a href="{{ release_url | safe }}" class="pure-menu-link warn" title="docs.rs failed to build {{ release_name }}">
148-
{{ "exclamation-triangle" | fas }} {{ release.version }}
148+
{{ "exclamation-triangle" | fas(fw=true) }} {{ release.version }}
149149
</a>
150150

151151
{# Otherwise just display the version #}

templates/releases/header.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,53 +24,53 @@ <h1 id="crate-title">{{ title }}</h1>
2424
<ul class="pure-menu-list">
2525
<li class="pure-menu-item">
2626
<a href="/releases" class="pure-menu-link{% if tab == 'recent' %} pure-menu-active{% endif %}">
27-
{{ "leaf" | fas }}
27+
{{ "leaf" | fas(fw=true) }}
2828
<span class="title"> Recent</span>
2929
</a>
3030
</li>
3131

3232
<li class="pure-menu-item">
3333
<a href="/releases/stars" class="pure-menu-link{% if tab == 'stars' %} pure-menu-active{% endif %}">
34-
{{ "star" | fas }}
34+
{{ "star" | fas(fw=true) }}
3535
<span class="title"> Stars</span>
3636
</a>
3737
</li>
3838

3939
<li class="pure-menu-item">
4040
<a href="/releases/recent-failures"
4141
class="pure-menu-link{% if tab == 'recent-failures' %} pure-menu-active{% endif %}">
42-
{{ "exclamation-triangle" | fas }}
42+
{{ "exclamation-triangle" | fas(fw=true) }}
4343
<span class="title"> Recent Failures</span>
4444
</a>
4545
</li>
4646

4747
<li class="pure-menu-item">
4848
<a href="/releases/failures"
4949
class="pure-menu-link{% if tab == 'failures' %} pure-menu-active{% endif %}">
50-
{{ "star" | far }}
50+
{{ "star" | far(fw=true) }}
5151
<span class="title"> Failures By Stars</span>
5252
</a>
5353
</li>
5454

5555
<li class="pure-menu-item">
5656
<a href="/releases/activity"
5757
class="pure-menu-link{% if tab == 'activity' %} pure-menu-active{% endif %}">
58-
{{ "chart-line" | fas }}
58+
{{ "chart-line" | fas(fw=true) }}
5959
<span class="title"> Activity</span>
6060
</a>
6161
</li>
6262

6363
<li class="pure-menu-item">
6464
<a href="/releases/queue" class="pure-menu-link{% if tab == 'queue' %} pure-menu-active{% endif %}">
65-
{{ "list" | fas }}
65+
{{ "list" | fas(fw=true) }}
6666
<span class="title"> Queue</span>
6767
</a>
6868
</li>
6969

7070
{%- if author -%}
7171
<li class="pure-menu-item">
7272
<a href="#" class="pure-menu-link{% if tab == 'author' %} pure-menu-active{% endif %}">
73-
{{ "user" | fas }}
73+
{{ "user" | fas(fw=true) }}
7474
<span class="title"> {{ author }}</span>
7575
</a>
7676
</li>

0 commit comments

Comments
 (0)