Browse Source

Add robots.txt

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
b0cc1ac042
3 changed files with 15 additions and 0 deletions
  1. +10
    -0
      src/site.rs
  2. +1
    -0
      src/templates/robots.txt
  3. +4
    -0
      tests/site.rs

+ 10
- 0
src/site.rs 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
- 0
src/templates/robots.txt View File

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

+ 4
- 0
tests/site.rs 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"));


Loading…
Cancel
Save