Skip to content

Commit 7a5cd2b

Browse files
committed
Consistentize the system for image URLs in CSS.
1 parent dd3952e commit 7a5cd2b

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

src/librustdoc/html/render/write_shared.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,42 +181,34 @@ pub(super) fn write_shared(
181181
cx.write_shared(SharedResource::InvocationSpecific { basename: p }, content, &options.emit)
182182
};
183183

184-
fn add_background_image_to_css(
185-
cx: &Context<'_>,
186-
css: &mut String,
187-
rule: &str,
188-
file: &'static str,
189-
) {
190-
css.push_str(&format!(
191-
"{} {{ background-image: url({}); }}",
192-
rule,
193-
SharedResource::ToolchainSpecific { basename: file }
184+
// Given "foo.svg", return e.g. "url(\"foo1.58.0.svg\")"
185+
fn ver_url(cx: &Context<'_>, basename: &'static str) -> String {
186+
format!(
187+
"url(\"{}\")",
188+
SharedResource::ToolchainSpecific { basename }
194189
.path(cx)
195190
.file_name()
196191
.unwrap()
197192
.to_str()
198193
.unwrap()
199-
))
194+
)
200195
}
201196

202-
// Add all the static files. These may already exist, but we just
203-
// overwrite them anyway to make sure that they're fresh and up-to-date.
204-
let mut rustdoc_css = static_files::RUSTDOC_CSS.to_owned();
205-
add_background_image_to_css(
206-
cx,
207-
&mut rustdoc_css,
208-
"details.undocumented[open] > summary::before, \
209-
details.rustdoc-toggle[open] > summary::before, \
210-
details.rustdoc-toggle[open] > summary.hideme::before",
211-
"toggle-minus.svg",
212-
);
213-
add_background_image_to_css(
197+
// We use the AUTOREPLACE mechanism to inject into our static JS and CSS certain
198+
// values that are only known at doc build time. Since this mechanism is somewhat
199+
// surprising when reading the code, please limit it to rustdoc.css.
200+
write_minify(
201+
"rustdoc.css",
202+
static_files::RUSTDOC_CSS
203+
.replace(
204+
"/* AUTOREPLACE: */url(\"toggle-minus.svg\")",
205+
&ver_url(cx, "toggle-minus.svg"),
206+
)
207+
.replace("/* AUTOREPLACE: */url(\"toggle-plus.svg\")", &ver_url(cx, "toggle-plus.svg"))
208+
.replace("/* AUTOREPLACE: */url(\"down-arrow.svg\")", &ver_url(cx, "down-arrow.svg")),
214209
cx,
215-
&mut rustdoc_css,
216-
"details.undocumented > summary::before, details.rustdoc-toggle > summary::before",
217-
"toggle-plus.svg",
218-
);
219-
write_minify("rustdoc.css", rustdoc_css, cx, options)?;
210+
options,
211+
)?;
220212

221213
// Add all the static files. These may already exist, but we just
222214
// overwrite them anyway to make sure that they're fresh and up-to-date.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ h2.small-section-header > .anchor {
825825
background-color: transparent;
826826
background-size: 20px;
827827
background-position: calc(100% - 1px) 56%;
828+
background-image: /* AUTOREPLACE: */url("down-arrow.svg");
828829
}
829830
.search-container > .top-button {
830831
position: absolute;
@@ -1611,6 +1612,16 @@ details.rustdoc-toggle[open] > summary.hideme > span {
16111612
display: none;
16121613
}
16131614

1615+
details.undocumented[open] > summary::before,
1616+
details.rustdoc-toggle[open] > summary::before,
1617+
details.rustdoc-toggle[open] > summary.hideme::before {
1618+
background-image: /* AUTOREPLACE: */url("toggle-minus.svg");
1619+
}
1620+
1621+
details.undocumented > summary::before, details.rustdoc-toggle > summary::before {
1622+
background-image: /* AUTOREPLACE: */url("toggle-plus.svg");
1623+
}
1624+
16141625
details.rustdoc-toggle[open] > summary::before,
16151626
details.rustdoc-toggle[open] > summary.hideme::before {
16161627
width: 17px;

src/librustdoc/html/templates/page.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@
4848
href="{{static_root_path | safe}}favicon{{page.resource_suffix}}.svg"> {#- -#}
4949
{%- endif -%}
5050
{{- layout.external_html.in_header | safe -}}
51-
<style type="text/css"> {#- -#}
52-
#crate-search{ {#- -#}
53-
background-image:url("{{static_root_path | safe}}down-arrow{{page.resource_suffix}}.svg"); {#- -#}
54-
} {#- -#}
55-
</style> {#- -#}
5651
</head> {#- -#}
5752
<body class="rustdoc {{page.css_class}}"> {#- -#}
5853
<!--[if lte IE 11]> {#- -#}

0 commit comments

Comments
 (0)