Skip to content

Commit db720ec

Browse files
authored
Rollup merge of rust-lang#57552 - GuillaumeGomez:default-images, r=QuietMisdreavus
Default images Add default rust logo (the image at the top of the sidebar) and default favicon. No more missing image or inexistent icon on the documentation tabs! r? @QuietMisdreavus
2 parents 68ea7e4 + b5d167f commit db720ec

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/librustdoc/html/layout.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
177177
root_path = page.root_path,
178178
css_class = page.css_class,
179179
logo = if layout.logo.is_empty() {
180-
String::new()
180+
format!("<a href='{}{}/index.html'>\
181+
<img src='{static_root_path}rust-logo{suffix}.png' alt='logo' width='100'></a>",
182+
static_root_path=static_root_path,
183+
suffix=page.resource_suffix)
181184
} else {
182185
format!("<a href='{}{}/index.html'>\
183186
<img src='{}' alt='logo' width='100'></a>",
@@ -188,7 +191,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
188191
description = page.description,
189192
keywords = page.keywords,
190193
favicon = if layout.favicon.is_empty() {
191-
String::new()
194+
format!(r#"<link rel="shortcut icon" href="{static_root_path}favicon{suffix}.ico">"#,
195+
static_root_path=static_root_path,
196+
suffix=page.resource_suffix)
192197
} else {
193198
format!(r#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
194199
},

src/librustdoc/html/render.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,14 @@ fn write_shared(
789789
themes.insert(theme.to_owned());
790790
}
791791

792+
if (*cx.shared).layout.logo.is_empty() {
793+
write(cx.dst.join(&format!("rust-logo{}.png", cx.shared.resource_suffix)),
794+
static_files::RUST_LOGO)?;
795+
}
796+
if (*cx.shared).layout.favicon.is_empty() {
797+
write(cx.dst.join(&format!("favicon{}.ico", cx.shared.resource_suffix)),
798+
static_files::RUST_FAVICON)?;
799+
}
792800
write(cx.dst.join(&format!("brush{}.svg", cx.shared.resource_suffix)),
793801
static_files::BRUSH_SVG)?;
794802
write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)),
@@ -2068,8 +2076,6 @@ impl Context {
20682076
themes.push(PathBuf::from("settings.css"));
20692077
let mut layout = self.shared.layout.clone();
20702078
layout.krate = String::new();
2071-
layout.logo = String::new();
2072-
layout.favicon = String::new();
20732079
try_err!(layout::render(&mut w, &layout,
20742080
&page, &sidebar, &settings,
20752081
self.shared.css_file_extension.is_some(),
22.7 KB
Binary file not shown.
5.62 KB
Loading

src/librustdoc/html/static_files.rs

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ pub static LICENSE_APACHE: &'static [u8] = include_bytes!("static/LICENSE-APACHE
5151
/// The contents of `LICENSE-MIT.txt`, the text of the MIT License.
5252
pub static LICENSE_MIT: &'static [u8] = include_bytes!("static/LICENSE-MIT.txt");
5353

54+
/// The contents of `rust-logo.png`, the default icon of the documentation.
55+
pub static RUST_LOGO: &'static [u8] = include_bytes!("static/rust-logo.png");
56+
/// The contents of `favicon.ico`, the default favicon of the documentation.
57+
pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico");
58+
5459
/// The built-in themes given to every documentation site.
5560
pub mod themes {
5661
/// The "light" theme, selected by default when no setting is available. Used as the basis for

0 commit comments

Comments
 (0)