Skip to content

Commit 5cf20ca

Browse files
Fix image link in the settings menu
1 parent f40aaa6 commit 5cf20ca

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/librustdoc/html/layout.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::path::PathBuf;
44

55
use externalfiles::ExternalHtml;
66

7+
use html::render::SlashChecker;
8+
79
#[derive(Clone)]
810
pub struct Layout {
911
pub logo: String,
@@ -176,16 +178,22 @@ pub fn render<T: fmt::Display, S: fmt::Display>(
176178
static_root_path = static_root_path,
177179
root_path = page.root_path,
178180
css_class = page.css_class,
179-
logo = if layout.logo.is_empty() {
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)
184-
} else {
185-
format!("<a href='{}{}/index.html'>\
186-
<img src='{}' alt='logo' width='100'></a>",
187-
page.root_path, layout.krate,
188-
layout.logo)
181+
logo = {
182+
let p = format!("{}{}", page.root_path, layout.krate);
183+
let p = SlashChecker(&p);
184+
if layout.logo.is_empty() {
185+
format!("<a href='{path}index.html'>\
186+
<img src='{static_root_path}rust-logo{suffix}.png' \
187+
alt='logo' width='100'></a>",
188+
path=p,
189+
static_root_path=static_root_path,
190+
suffix=page.resource_suffix)
191+
} else {
192+
format!("<a href='{}index.html'>\
193+
<img src='{}' alt='logo' width='100'></a>",
194+
p,
195+
layout.logo)
196+
}
189197
},
190198
title = page.title,
191199
description = page.description,

src/librustdoc/html/render.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ use minifier;
7373
/// A pair of name and its optional document.
7474
pub type NameDoc = (String, Option<String>);
7575

76+
pub struct SlashChecker<'a>(pub &'a str);
77+
78+
impl<'a> Display for SlashChecker<'a> {
79+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
80+
if !self.0.ends_with("/") && !self.0.is_empty() {
81+
write!(f, "{}/", self.0)
82+
} else {
83+
write!(f, "{}", self.0)
84+
}
85+
}
86+
}
87+
7688
/// Major driving force in all rustdoc rendering. This contains information
7789
/// about where in the tree-like hierarchy rendering is occurring and controls
7890
/// how the current page is being rendered.
@@ -1140,7 +1152,8 @@ themePicker.onblur = handleThemeButtonsBlur;
11401152
krates
11411153
.iter()
11421154
.map(|s| {
1143-
format!("<li><a href=\"{}/index.html\">{}</li>", s, s)
1155+
format!("<li><a href=\"{}index.html\">{}</li>",
1156+
SlashChecker(s), s)
11441157
})
11451158
.collect::<String>());
11461159
try_err!(layout::render(&mut w, &cx.shared.layout,
@@ -2074,8 +2087,7 @@ impl Context {
20742087
let mut themes = self.shared.themes.clone();
20752088
let sidebar = "<p class='location'>Settings</p><div class='sidebar-elems'></div>";
20762089
themes.push(PathBuf::from("settings.css"));
2077-
let mut layout = self.shared.layout.clone();
2078-
layout.krate = String::new();
2090+
let layout = self.shared.layout.clone();
20792091
try_err!(layout::render(&mut w, &layout,
20802092
&page, &sidebar, &settings,
20812093
self.shared.css_file_extension.is_some(),
@@ -2454,7 +2466,7 @@ impl<'a> fmt::Display for Item<'a> {
24542466

24552467
fn item_path(ty: ItemType, name: &str) -> String {
24562468
match ty {
2457-
ItemType::Module => format!("{}/index.html", name),
2469+
ItemType::Module => format!("{}index.html", SlashChecker(name)),
24582470
_ => format!("{}.{}.html", ty.css_class(), name),
24592471
}
24602472
}

src/test/rustdoc/keyword.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// @has foo/keyword.match.html '//a[@class="keyword"]' 'match'
88
// @has foo/keyword.match.html '//span[@class="in-band"]' 'Keyword match'
99
// @has foo/keyword.match.html '//section[@id="main"]//div[@class="docblock"]//p' 'this is a test!'
10-
// @!has foo/index.html '//a/@href' 'foo/index.html'
10+
// @has foo/index.html '//a/@href' '../foo/index.html'
1111
// @!has foo/foo/index.html
1212
// @!has-dir foo/foo
1313
#[doc(keyword = "match")]

0 commit comments

Comments
 (0)