From d8995c156c2affac7800ac285a5e9702c027d2a0 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 19 Mar 2017 19:40:31 +0900 Subject: [PATCH] Add sections to sitemap --- src/site.rs | 2 ++ src/templates/sitemap.xml | 7 ++++++- tests/site.rs | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/site.rs b/src/site.rs index 48793672..7679b513 100644 --- a/src/site.rs +++ b/src/site.rs @@ -335,6 +335,8 @@ impl Site { fn render_sitemap(&self) -> Result<()> { let mut context = Context::new(); context.add("pages", &self.pages.values().collect::>()); + context.add("sections", &self.sections.values().collect::>()); + // TODO: add categories and tags pages let sitemap = self.templates.render("sitemap.xml", &context)?; create_file(self.output_path.join("sitemap.xml"), &sitemap)?; diff --git a/src/templates/sitemap.xml b/src/templates/sitemap.xml index 0dadd5c4..24b7ccf9 100644 --- a/src/templates/sitemap.xml +++ b/src/templates/sitemap.xml @@ -1,10 +1,15 @@ {% for page in pages %} - {{ page.permalink }} + {{ page.permalink | safe }} {% if page.date %} {{ page.date }} {% endif %} {% endfor %} + {% for section in sections %} + + {{ section.permalink | safe }} + + {% endfor %} diff --git a/tests/site.rs b/tests/site.rs index 1c651621..f2d06fc2 100644 --- a/tests/site.rs +++ b/tests/site.rs @@ -78,7 +78,6 @@ macro_rules! file_contains { let mut file = File::open(&path).unwrap(); let mut s = String::new(); file.read_to_string(&mut s).unwrap(); - s.contains($text) } } @@ -117,6 +116,10 @@ fn test_can_build_site_without_live_reload() { // no live reload code assert_eq!(file_contains!(public, "index.html", "/livereload.js?port=1112&mindelay=10"), false); + + // Both pages and sections are in the sitemap + assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/posts/simple")); + assert!(file_contains!(public, "sitemap.xml", "https://replace-this-with-your-url.com/posts")); } #[test]