Skip to content

Emit description and keyword metadata from rustdoc #16254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand All @@ -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>

Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 32 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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> "));
}
_ => {}
};
Expand Down Expand Up @@ -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())
}