Skip to content

Commit

Permalink
Rollup merge of #78094 - camelid:rustdoc-fix-source-title, r=jyn514
Browse files Browse the repository at this point in the history
rustdoc: Show the correct source filename in page titles, without `.html`

Previously the title would be

    lib.rs.html -- source

if `lib.rs` was the actual source filename. Now the title is

    lib.rs - source
  • Loading branch information
JohnTitor authored Oct 21, 2020
2 parents 89c98cd + 243c8e9 commit 72ae00b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> SourceCollector<'a> {
};

// Remove the utf-8 BOM if any
if contents.starts_with("\u{feff}") {
if contents.starts_with('\u{feff}') {
contents.drain(..3);
}

Expand All @@ -99,16 +99,15 @@ impl<'a> SourceCollector<'a> {
href.push('/');
});
self.scx.ensure_dir(&cur)?;
let mut fname = p.file_name().expect("source has no filename").to_os_string();

let src_fname = p.file_name().expect("source has no filename").to_os_string();
let mut fname = src_fname.clone();
fname.push(".html");
cur.push(&fname);
href.push_str(&fname.to_string_lossy());

let title = format!(
"{} -- source",
cur.file_name().expect("failed to get file name").to_string_lossy()
);
let desc = format!("Source to the Rust file `{}`.", filename);
let title = format!("{} - source", src_fname.to_string_lossy());
let desc = format!("Source of the Rust file `{}`.", filename);
let page = layout::Page {
title: &title,
css_class: "source",
Expand Down

0 comments on commit 72ae00b

Please sign in to comment.