auto merge of #16254 : brson/rust/rustdocmeta, r=aturon

This teach rustdoc to add `<meta name="description">` and `<meta name="keywords">` tags to crate docs. Description is important for search engines because they display it as the page description. Keywords are less useful but still generally recommended.

This also changes the "stability dashboard" link to just say "stability", because the current link takes up a lot of space.

cc https://github.com/rust-lang/rust/issues/12466
This commit is contained in:
bors 2014-08-06 04:56:25 +00:00
commit 223c043110
2 changed files with 38 additions and 3 deletions

View File

@ -26,6 +26,8 @@ pub struct Page<'a> {
pub title: &'a str,
pub ty: &'a str,
pub root_path: &'a str,
pub description: &'a str,
pub keywords: &'a str
}
pub fn render<T: fmt::Show, S: fmt::Show>(
@ -38,8 +40,9 @@ r##"<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="The {krate} library documentation.">
<meta name="generator" content="rustdoc">
<meta name="description" content="{description}">
<meta name="keywords" content="{keywords}">
<title>{title}</title>
@ -135,6 +138,8 @@ r##"<!DOCTYPE html>
layout.logo)
},
title = page.title,
description = page.description,
keywords = page.keywords,
favicon = if layout.favicon.len() == 0 {
"".to_string()
} else {

View File

@ -742,10 +742,13 @@ 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(),
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)));
@ -1072,10 +1075,14 @@ 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",
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)));
@ -1120,10 +1127,25 @@ 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 keywords = make_item_keywords(it);
let page = layout::Page {
ty: shortty(it).to_static_str(),
ty: tyname,
root_path: cx.root_path.as_slice(),
title: title.as_slice(),
description: desc.as_slice(),
keywords: keywords.as_slice(),
};
markdown::reset_headers();
@ -1311,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, "<a href='stability.html'>[stability dashboard]</a> "));
try!(write!(fmt, "<a href='stability.html'>[stability]</a> "));
}
_ => {}
};
@ -2152,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())
}