Add robots.txt

This commit is contained in:
Vincent Prouillet 2017-03-20 21:40:03 +09:00
parent eb6fa3c314
commit b0cc1ac042
3 changed files with 15 additions and 0 deletions

View file

@ -21,6 +21,7 @@ lazy_static! {
tera.add_raw_templates(vec![ tera.add_raw_templates(vec![
("rss.xml", include_str!("templates/rss.xml")), ("rss.xml", include_str!("templates/rss.xml")),
("sitemap.xml", include_str!("templates/sitemap.xml")), ("sitemap.xml", include_str!("templates/sitemap.xml")),
("robots.txt", include_str!("templates/robots.txt")),
]).unwrap(); ]).unwrap();
tera tera
}; };
@ -296,10 +297,19 @@ impl Site {
self.render_rss_feed()?; self.render_rss_feed()?;
} }
self.render_robots()?;
self.render_sections()?; self.render_sections()?;
self.copy_static_directory() self.copy_static_directory()
} }
fn render_robots(&self) -> Result<()> {
create_file(
self.output_path.join("robots.txt"),
&self.templates.render("robots.txt", &Context::new())?
)
}
/// Render the /{categories, list} pages and each individual category/tag page /// Render the /{categories, list} pages and each individual category/tag page
/// They are the same thing fundamentally, a list of pages with something in common /// They are the same thing fundamentally, a list of pages with something in common
fn render_categories_and_tags(&self, kind: RenderList) -> Result<()> { fn render_categories_and_tags(&self, kind: RenderList) -> Result<()> {

1
src/templates/robots.txt Normal file
View file

@ -0,0 +1 @@
User-agent: *

View file

@ -99,6 +99,7 @@ fn test_can_build_site_without_live_reload() {
assert!(file_exists!(public, "index.html")); assert!(file_exists!(public, "index.html"));
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt"));
assert!(file_exists!(public, "a-fixed-url/index.html")); assert!(file_exists!(public, "a-fixed-url/index.html"));
assert!(file_exists!(public, "posts/python/index.html")); assert!(file_exists!(public, "posts/python/index.html"));
@ -140,6 +141,7 @@ fn test_can_build_site_with_live_reload() {
assert!(file_exists!(public, "index.html")); assert!(file_exists!(public, "index.html"));
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt"));
assert!(file_exists!(public, "a-fixed-url/index.html")); assert!(file_exists!(public, "a-fixed-url/index.html"));
assert!(file_exists!(public, "posts/python/index.html")); assert!(file_exists!(public, "posts/python/index.html"));
@ -186,6 +188,7 @@ fn test_can_build_site_with_categories() {
assert!(file_exists!(public, "index.html")); assert!(file_exists!(public, "index.html"));
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt"));
assert!(file_exists!(public, "a-fixed-url/index.html")); assert!(file_exists!(public, "a-fixed-url/index.html"));
assert!(file_exists!(public, "posts/python/index.html")); assert!(file_exists!(public, "posts/python/index.html"));
@ -237,6 +240,7 @@ fn test_can_build_site_with_tags() {
assert!(file_exists!(public, "index.html")); assert!(file_exists!(public, "index.html"));
assert!(file_exists!(public, "sitemap.xml")); assert!(file_exists!(public, "sitemap.xml"));
assert!(file_exists!(public, "robots.txt"));
assert!(file_exists!(public, "a-fixed-url/index.html")); assert!(file_exists!(public, "a-fixed-url/index.html"));
assert!(file_exists!(public, "posts/python/index.html")); assert!(file_exists!(public, "posts/python/index.html"));