From 08d44f5512e624eadfedf32d41f19ece13dd5fb4 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Aug 2014 13:53:33 -0700 Subject: [PATCH 1/4] rustdoc: Use more descriptive description metadata. This text appears in and improves search results. cc #12466 --- src/librustdoc/html/layout.rs | 4 +++- src/librustdoc/html/render.rs | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 70e9d004160..35157255069 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -26,6 +26,7 @@ pub struct Page<'a> { pub title: &'a str, pub ty: &'a str, pub root_path: &'a str, + pub description: &'a str } pub fn render( @@ -38,8 +39,8 @@ r##" - + {title} @@ -135,6 +136,7 @@ r##" layout.logo) }, title = page.title, + description = page.description, favicon = if layout.favicon.len() == 0 { "".to_string() } else { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1700354e329..47e91470612 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -742,8 +742,10 @@ impl<'a> SourceCollector<'a> { let mut w = BufferedWriter::new(try!(File::create(&cur))); let title = format!("{} -- source", cur.filename_display()); + let desc = format!("Source to the Rust file `{}`.", filename); let page = layout::Page { title: title.as_slice(), + description: desc.as_slice(), ty: "source", root_path: root_path.as_slice(), }; @@ -1072,8 +1074,11 @@ impl Context { try!(stability.encode(&mut json::Encoder::new(&mut json_out))); let title = stability.name.clone().append(" - Stability dashboard"); + let desc = format!("API stability overview for the Rust `{}` crate.", + this.layout.krate); let page = layout::Page { ty: "mod", + description: desc.as_slice(), root_path: this.root_path.as_slice(), title: title.as_slice(), }; @@ -1120,8 +1125,21 @@ impl Context { title.push_str(it.name.get_ref().as_slice()); } title.push_str(" - Rust"); + let tyname = shortty(it).to_static_str(); + let is_crate = match it.inner { + clean::ModuleItem(clean::Module { items: _, is_crate: true }) => true, + _ => false + }; + let desc = if is_crate { + format!("API documentation for the Rust `{}` crate.", + cx.layout.krate) + } else { + format!("API documentation for the Rust `{}` {} in crate `{}`.", + it.name.get_ref(), tyname, cx.layout.krate) + }; let page = layout::Page { - ty: shortty(it).to_static_str(), + ty: tyname, + description: desc.as_slice(), root_path: cx.root_path.as_slice(), title: title.as_slice(), }; From 2b0a15494ae24f7f131c8cbe14ca00638b1ae5f9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Aug 2014 14:15:47 -0700 Subject: [PATCH 2/4] rustdoc: Put field instantiation in declaration order. cc #12466 --- src/librustdoc/html/render.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 47e91470612..d35d074daea 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -745,9 +745,9 @@ impl<'a> SourceCollector<'a> { let desc = format!("Source to the Rust file `{}`.", filename); let page = layout::Page { title: title.as_slice(), - description: desc.as_slice(), ty: "source", root_path: root_path.as_slice(), + description: desc.as_slice(), }; try!(layout::render(&mut w as &mut Writer, &self.cx.layout, &page, &(""), &Source(contents))); @@ -1078,9 +1078,9 @@ impl Context { this.layout.krate); let page = layout::Page { ty: "mod", - description: desc.as_slice(), root_path: this.root_path.as_slice(), title: title.as_slice(), + description: desc.as_slice(), }; let html_dst = &this.dst.join("stability.html"); let mut html_out = BufferedWriter::new(try!(File::create(html_dst))); @@ -1139,9 +1139,9 @@ impl Context { }; let page = layout::Page { ty: tyname, - description: desc.as_slice(), root_path: cx.root_path.as_slice(), title: title.as_slice(), + description: desc.as_slice(), }; markdown::reset_headers(); From 57e53d5c2f761a09c1d37d54dd93dc7109b329ab Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Aug 2014 14:30:06 -0700 Subject: [PATCH 3/4] rustdoc: Emit keywords for all crate pages cc #12466 --- src/librustdoc/html/layout.rs | 5 ++++- src/librustdoc/html/render.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 35157255069..2e1b8d32dd3 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -26,7 +26,8 @@ pub struct Page<'a> { pub title: &'a str, pub ty: &'a str, pub root_path: &'a str, - pub description: &'a str + pub description: &'a str, + pub keywords: &'a str } pub fn render( @@ -41,6 +42,7 @@ r##" + {title} @@ -137,6 +139,7 @@ r##" }, title = page.title, description = page.description, + keywords = page.keywords, favicon = if layout.favicon.len() == 0 { "".to_string() } else { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d35d074daea..e3a776e04db 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -748,6 +748,7 @@ impl<'a> SourceCollector<'a> { ty: "source", root_path: root_path.as_slice(), description: desc.as_slice(), + keywords: get_basic_keywords(), }; try!(layout::render(&mut w as &mut Writer, &self.cx.layout, &page, &(""), &Source(contents))); @@ -1081,6 +1082,7 @@ impl Context { root_path: this.root_path.as_slice(), title: title.as_slice(), description: desc.as_slice(), + keywords: get_basic_keywords(), }; let html_dst = &this.dst.join("stability.html"); let mut html_out = BufferedWriter::new(try!(File::create(html_dst))); @@ -1137,11 +1139,13 @@ impl Context { format!("API documentation for the Rust `{}` {} in crate `{}`.", it.name.get_ref(), tyname, cx.layout.krate) }; + let keywords = make_item_keywords(it); let page = layout::Page { ty: tyname, root_path: cx.root_path.as_slice(), title: title.as_slice(), description: desc.as_slice(), + keywords: keywords.as_slice(), }; markdown::reset_headers(); @@ -2170,3 +2174,11 @@ fn ignore_private_item(it: &clean::Item) -> bool { _ => false, } } + +fn get_basic_keywords() -> &'static str { + "rust, rustlang, rust-lang" +} + +fn make_item_keywords(it: &clean::Item) -> String { + format!("{}, {}", get_basic_keywords(), it.name.get_ref()) +} From bcdc8fb812aefd053d57b99357cf5769a4959ae8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 4 Aug 2014 14:31:53 -0700 Subject: [PATCH 4/4] rustdoc: Just "stability" instead of "stability dashboard" The words "stability dashboard" take up too much space on small screens. --- src/librustdoc/html/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e3a776e04db..76e18d5258c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1333,7 +1333,7 @@ impl<'a> fmt::Show for Item<'a> { // Write stability dashboard link match self.item.inner { clean::ModuleItem(ref m) if m.is_crate => { - try!(write!(fmt, "[stability dashboard] ")); + try!(write!(fmt, "[stability] ")); } _ => {} };