Skip to content

Commit 57e53d5

Browse files
committed
rustdoc: Emit keywords for all crate pages
cc rust-lang#12466
1 parent 2b0a154 commit 57e53d5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/librustdoc/html/layout.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ 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
29+
pub description: &'a str,
30+
pub keywords: &'a str
3031
}
3132

3233
pub fn render<T: fmt::Show, S: fmt::Show>(
@@ -41,6 +42,7 @@ r##"<!DOCTYPE html>
4142
<meta name="viewport" content="width=device-width, initial-scale=1.0">
4243
<meta name="generator" content="rustdoc">
4344
<meta name="description" content="{description}">
45+
<meta name="keywords" content="{keywords}">
4446
4547
<title>{title}</title>
4648
@@ -137,6 +139,7 @@ r##"<!DOCTYPE html>
137139
},
138140
title = page.title,
139141
description = page.description,
142+
keywords = page.keywords,
140143
favicon = if layout.favicon.len() == 0 {
141144
"".to_string()
142145
} else {

src/librustdoc/html/render.rs

+12
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ impl<'a> SourceCollector<'a> {
748748
ty: "source",
749749
root_path: root_path.as_slice(),
750750
description: desc.as_slice(),
751+
keywords: get_basic_keywords(),
751752
};
752753
try!(layout::render(&mut w as &mut Writer, &self.cx.layout,
753754
&page, &(""), &Source(contents)));
@@ -1081,6 +1082,7 @@ impl Context {
10811082
root_path: this.root_path.as_slice(),
10821083
title: title.as_slice(),
10831084
description: desc.as_slice(),
1085+
keywords: get_basic_keywords(),
10841086
};
10851087
let html_dst = &this.dst.join("stability.html");
10861088
let mut html_out = BufferedWriter::new(try!(File::create(html_dst)));
@@ -1137,11 +1139,13 @@ impl Context {
11371139
format!("API documentation for the Rust `{}` {} in crate `{}`.",
11381140
it.name.get_ref(), tyname, cx.layout.krate)
11391141
};
1142+
let keywords = make_item_keywords(it);
11401143
let page = layout::Page {
11411144
ty: tyname,
11421145
root_path: cx.root_path.as_slice(),
11431146
title: title.as_slice(),
11441147
description: desc.as_slice(),
1148+
keywords: keywords.as_slice(),
11451149
};
11461150

11471151
markdown::reset_headers();
@@ -2170,3 +2174,11 @@ fn ignore_private_item(it: &clean::Item) -> bool {
21702174
_ => false,
21712175
}
21722176
}
2177+
2178+
fn get_basic_keywords() -> &'static str {
2179+
"rust, rustlang, rust-lang"
2180+
}
2181+
2182+
fn make_item_keywords(it: &clean::Item) -> String {
2183+
format!("{}, {}", get_basic_keywords(), it.name.get_ref())
2184+
}

0 commit comments

Comments
 (0)