From b0cc1ac042f0ed7f9f8b3b74c81b71afbf7e19da Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Mon, 20 Mar 2017 21:40:03 +0900 Subject: [PATCH] Add robots.txt --- src/site.rs | 10 ++++++++++ src/templates/robots.txt | 1 + tests/site.rs | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 src/templates/robots.txt diff --git a/src/site.rs b/src/site.rs index f2e4443..b29174f 100644 --- a/src/site.rs +++ b/src/site.rs @@ -21,6 +21,7 @@ lazy_static! { tera.add_raw_templates(vec![ ("rss.xml", include_str!("templates/rss.xml")), ("sitemap.xml", include_str!("templates/sitemap.xml")), + ("robots.txt", include_str!("templates/robots.txt")), ]).unwrap(); tera }; @@ -296,10 +297,19 @@ impl Site { self.render_rss_feed()?; } + self.render_robots()?; + self.render_sections()?; 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 /// They are the same thing fundamentally, a list of pages with something in common fn render_categories_and_tags(&self, kind: RenderList) -> Result<()> { diff --git a/src/templates/robots.txt b/src/templates/robots.txt new file mode 100644 index 0000000..7d329b1 --- /dev/null +++ b/src/templates/robots.txt @@ -0,0 +1 @@ +User-agent: * diff --git a/tests/site.rs b/tests/site.rs index 1c9d9d1..3bb8412 100644 --- a/tests/site.rs +++ b/tests/site.rs @@ -99,6 +99,7 @@ fn test_can_build_site_without_live_reload() { assert!(file_exists!(public, "index.html")); 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, "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, "sitemap.xml")); + assert!(file_exists!(public, "robots.txt")); assert!(file_exists!(public, "a-fixed-url/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, "sitemap.xml")); + assert!(file_exists!(public, "robots.txt")); assert!(file_exists!(public, "a-fixed-url/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, "sitemap.xml")); + assert!(file_exists!(public, "robots.txt")); assert!(file_exists!(public, "a-fixed-url/index.html")); assert!(file_exists!(public, "posts/python/index.html"));