Skip to content

Commit 13235dc

Browse files
committed
rustdoc: load icons from css instead of inline
This cuts the HTML overhead for a page by about 1KiB, significantly reducing the overall size of the docs bundle.
1 parent dac788f commit 13235dc

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'tcx> Context<'tcx> {
231231
rust_logo: has_doc_flag(self.tcx(), LOCAL_CRATE.as_def_id(), sym::rust_logo),
232232
};
233233
let mut page_buffer = Buffer::html();
234-
print_item(self, it, &mut page_buffer, &page);
234+
print_item(self, it, &mut page_buffer);
235235
layout::render(
236236
&clone_shared.layout,
237237
&page,

src/librustdoc/html/render/print_item.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ use crate::html::format::{
3131
display_fn, join_with_double_colon, print_abi_with_space, print_constness_with_space,
3232
print_where_clause, visibility_print_with_space, Buffer, Ending, PrintWithSpace,
3333
};
34-
use crate::html::layout::Page;
34+
use crate::html::highlight;
3535
use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine};
3636
use crate::html::render::{document_full, document_item_info};
3737
use crate::html::url_parts_builder::UrlPartsBuilder;
38-
use crate::html::{highlight, static_files};
3938

4039
use askama::Template;
4140
use itertools::Itertools;
@@ -157,8 +156,6 @@ struct PathComponent {
157156
#[derive(Template)]
158157
#[template(path = "print_item.html")]
159158
struct ItemVars<'a> {
160-
static_root_path: &'a str,
161-
clipboard_svg: &'static static_files::StaticFile,
162159
typ: &'a str,
163160
name: &'a str,
164161
item_type: &'a str,
@@ -178,12 +175,7 @@ fn print_where_clause_and_check<'a, 'tcx: 'a>(
178175
len_before != buffer.len()
179176
}
180177

181-
pub(super) fn print_item(
182-
cx: &mut Context<'_>,
183-
item: &clean::Item,
184-
buf: &mut Buffer,
185-
page: &Page<'_>,
186-
) {
178+
pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buffer) {
187179
debug_assert!(!item.is_stripped());
188180
let typ = match *item.kind {
189181
clean::ModuleItem(_) => {
@@ -252,8 +244,6 @@ pub(super) fn print_item(
252244
};
253245

254246
let item_vars = ItemVars {
255-
static_root_path: &page.get_static_root_path(),
256-
clipboard_svg: &static_files::STATIC_FILES.clipboard_svg,
257247
typ,
258248
name: item.name.as_ref().unwrap().as_str(),
259249
item_type: &item.type_().to_string(),

src/librustdoc/html/static/css/rustdoc.css

+18-2
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,16 @@ a.tooltip:hover::after {
16031603
border-color: var(--settings-button-border-focus);
16041604
}
16051605

1606+
#settings-menu > a {
1607+
line-height: 0;
1608+
font-size: 0;
1609+
}
1610+
#settings-menu > a:before {
1611+
content: url('wheel-63255fc4502dca9a.svg');
1612+
width: 22px;
1613+
height: 22px;
1614+
}
1615+
16061616
#sidebar-button > a:before {
16071617
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" \
16081618
fill="none" stroke="black">\
@@ -1622,11 +1632,17 @@ a.tooltip:hover::after {
16221632
padding-left: 2px;
16231633
border: 0;
16241634
width: 33px;
1635+
line-height: 0;
1636+
font-size: 0;
16251637
}
1626-
#copy-path > img {
1638+
1639+
#copy-path:before {
16271640
filter: var(--copy-path-img-filter);
1641+
content: url('clipboard-24048e6d87f63d07.svg');
1642+
width: 19px;
1643+
height: 18px;
16281644
}
1629-
#copy-path:hover > img {
1645+
#copy-path:hover:before {
16301646
filter: var(--copy-path-img-hover-filter);
16311647
}
16321648

Loading
+1-1
Loading

src/librustdoc/html/templates/page.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ <h2>Files</h2> {# #}
139139
</div> {# #}
140140
<div id="settings-menu" tabindex="-1"> {# #}
141141
<a href="{{page.root_path|safe}}settings.html" title="settings"> {# #}
142-
<img width="22" height="22" alt="Change settings" {#+ #}
143-
src="{{static_root_path|safe}}{{files.wheel_svg}}"> {# #}
142+
Settings {# #}
144143
</a> {# #}
145144
</div> {# #}
146145
</form> {# #}

src/librustdoc/html/templates/print_item.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ <h1>
77
{% endfor %}
88
<a class="{{item_type}}" href="#">{{name}}</a> {# #}
99
<button id="copy-path" title="Copy item path to clipboard"> {# #}
10-
<img src="{{static_root_path|safe}}{{clipboard_svg}}" {#+ #}
11-
width="19" height="18" {#+ #}
12-
alt="Copy item path"> {# #}
10+
Copy item path {# #}
1311
</button> {# #}
1412
</h1> {# #}
1513
<span class="out-of-band">

src/librustdoc/html/templates/sidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h2 class="location"> {# #}
55
{% endif %}
66
<div class="sidebar-elems">
77
{% if is_crate %}
8-
<ul class="block">
8+
<ul class="block"> {# #}
99
<li><a id="all-types" href="all.html">All Items</a></li> {# #}
1010
</ul>
1111
{% endif %}

0 commit comments

Comments
 (0)