Skip to content

Commit

Permalink
Don't let robots index the print.html (rust-lang#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch authored and Dylan-DPC committed May 7, 2019
1 parent 126f065 commit 286891c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>{{ title }}</title>
{{#if is_print }}
<meta name="robots" content="noindex" />
{{/if}}

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="description" content="{{ description }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down
14 changes: 14 additions & 0 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ fn theme_dir_overrides_work_correctly() {
dummy_book::assert_contains_strings(built_index, &["This is a modified index.hbs!"]);
}


#[test]
fn no_index_for_print_html() {
let temp = DummyBook::new().build().unwrap();
let md = MDBook::load(temp.path()).unwrap();
md.build().unwrap();

let print_html = temp.path().join("book/print.html");
assert_contains_strings(print_html, &[r##"noindex"##]);

let index_html = temp.path().join("book/index.html");
assert_doesnt_contain_strings(index_html, &[r##"noindex"##]);
}

#[cfg(feature = "search")]
mod search {
extern crate serde_json;
Expand Down

0 comments on commit 286891c

Please sign in to comment.