Skip to content

Commit 08d44f5

Browse files
committed
rustdoc: Use more descriptive description metadata.
This text appears in and improves search results. cc rust-lang#12466
1 parent efe1f7e commit 08d44f5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/librustdoc/html/layout.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct Page<'a> {
2626
pub title: &'a str,
2727
pub ty: &'a str,
2828
pub root_path: &'a str,
29+
pub description: &'a str
2930
}
3031

3132
pub fn render<T: fmt::Show, S: fmt::Show>(
@@ -38,8 +39,8 @@ r##"<!DOCTYPE html>
3839
<head>
3940
<meta charset="utf-8">
4041
<meta name="viewport" content="width=device-width, initial-scale=1.0">
41-
<meta name="description" content="The {krate} library documentation.">
4242
<meta name="generator" content="rustdoc">
43+
<meta name="description" content="{description}">
4344
4445
<title>{title}</title>
4546
@@ -135,6 +136,7 @@ r##"<!DOCTYPE html>
135136
layout.logo)
136137
},
137138
title = page.title,
139+
description = page.description,
138140
favicon = if layout.favicon.len() == 0 {
139141
"".to_string()
140142
} else {

src/librustdoc/html/render.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,10 @@ impl<'a> SourceCollector<'a> {
742742
let mut w = BufferedWriter::new(try!(File::create(&cur)));
743743

744744
let title = format!("{} -- source", cur.filename_display());
745+
let desc = format!("Source to the Rust file `{}`.", filename);
745746
let page = layout::Page {
746747
title: title.as_slice(),
748+
description: desc.as_slice(),
747749
ty: "source",
748750
root_path: root_path.as_slice(),
749751
};
@@ -1072,8 +1074,11 @@ impl Context {
10721074
try!(stability.encode(&mut json::Encoder::new(&mut json_out)));
10731075

10741076
let title = stability.name.clone().append(" - Stability dashboard");
1077+
let desc = format!("API stability overview for the Rust `{}` crate.",
1078+
this.layout.krate);
10751079
let page = layout::Page {
10761080
ty: "mod",
1081+
description: desc.as_slice(),
10771082
root_path: this.root_path.as_slice(),
10781083
title: title.as_slice(),
10791084
};
@@ -1120,8 +1125,21 @@ impl Context {
11201125
title.push_str(it.name.get_ref().as_slice());
11211126
}
11221127
title.push_str(" - Rust");
1128+
let tyname = shortty(it).to_static_str();
1129+
let is_crate = match it.inner {
1130+
clean::ModuleItem(clean::Module { items: _, is_crate: true }) => true,
1131+
_ => false
1132+
};
1133+
let desc = if is_crate {
1134+
format!("API documentation for the Rust `{}` crate.",
1135+
cx.layout.krate)
1136+
} else {
1137+
format!("API documentation for the Rust `{}` {} in crate `{}`.",
1138+
it.name.get_ref(), tyname, cx.layout.krate)
1139+
};
11231140
let page = layout::Page {
1124-
ty: shortty(it).to_static_str(),
1141+
ty: tyname,
1142+
description: desc.as_slice(),
11251143
root_path: cx.root_path.as_slice(),
11261144
title: title.as_slice(),
11271145
};

0 commit comments

Comments
 (0)