Skip to content

Commit

Permalink
Rollup merge of rust-lang#57552 - GuillaumeGomez:default-images, r=Qu…
Browse files Browse the repository at this point in the history
…ietMisdreavus

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
  • Loading branch information
Centril authored Jan 22, 2019
2 parents e437861 + b5d167f commit e3d3cff
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
root_path = page.root_path,
css_class = page.css_class,
logo = if layout.logo.is_empty() {
String::new()
format!("<a href='{}{}/index.html'>\
<img src='{static_root_path}rust-logo{suffix}.png' alt='logo' width='100'></a>",
static_root_path=static_root_path,
suffix=page.resource_suffix)
} else {
format!("<a href='{}{}/index.html'>\
<img src='{}' alt='logo' width='100'></a>",
Expand All @@ -188,7 +191,9 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
description = page.description,
keywords = page.keywords,
favicon = if layout.favicon.is_empty() {
String::new()
format!(r#"<link rel="shortcut icon" href="{static_root_path}favicon{suffix}.ico">"#,
static_root_path=static_root_path,
suffix=page.resource_suffix)
} else {
format!(r#"<link rel="shortcut icon" href="{}">"#, layout.favicon)
},
Expand Down
10 changes: 8 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,14 @@ fn write_shared(
themes.insert(theme.to_owned());
}

if (*cx.shared).layout.logo.is_empty() {
write(cx.dst.join(&format!("rust-logo{}.png", cx.shared.resource_suffix)),
static_files::RUST_LOGO)?;
}
if (*cx.shared).layout.favicon.is_empty() {
write(cx.dst.join(&format!("favicon{}.ico", cx.shared.resource_suffix)),
static_files::RUST_FAVICON)?;
}
write(cx.dst.join(&format!("brush{}.svg", cx.shared.resource_suffix)),
static_files::BRUSH_SVG)?;
write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)),
Expand Down Expand Up @@ -2068,8 +2076,6 @@ impl Context {
themes.push(PathBuf::from("settings.css"));
let mut layout = self.shared.layout.clone();
layout.krate = String::new();
layout.logo = String::new();
layout.favicon = String::new();
try_err!(layout::render(&mut w, &layout,
&page, &sidebar, &settings,
self.shared.css_file_extension.is_some(),
Expand Down
Binary file added src/librustdoc/html/static/favicon.ico
Binary file not shown.
Binary file added src/librustdoc/html/static/rust-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub static LICENSE_APACHE: &'static [u8] = include_bytes!("static/LICENSE-APACHE
/// The contents of `LICENSE-MIT.txt`, the text of the MIT License.
pub static LICENSE_MIT: &'static [u8] = include_bytes!("static/LICENSE-MIT.txt");

/// The contents of `rust-logo.png`, the default icon of the documentation.
pub static RUST_LOGO: &'static [u8] = include_bytes!("static/rust-logo.png");
/// The contents of `favicon.ico`, the default favicon of the documentation.
pub static RUST_FAVICON: &'static [u8] = include_bytes!("static/favicon.ico");

/// The built-in themes given to every documentation site.
pub mod themes {
/// The "light" theme, selected by default when no setting is available. Used as the basis for
Expand Down

0 comments on commit e3d3cff

Please sign in to comment.