From c61518225b7b4a6bc381a0cc4acfe5851bbac488 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sat, 15 Jul 2017 12:51:32 +0900 Subject: [PATCH] Fix RSS feed; close #101 --- CHANGELOG.md | 7 ++++++- components/site/src/lib.rs | 4 ++-- components/site/test_site/config.toml | 2 ++ .../site/test_site/content/posts/simple.md | 2 +- components/site/tests/site.rs | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de964660..7978f77e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog -## 0.1.0 (unreleased) +## 0.1.1 (unreleased) + +- Fix RSS feed not behaving (https://github.com/Keats/gutenberg/issues/101) + + +## 0.1.0 (2017-07-14) - Parallelize all the things - Add weight sorting diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 10a2b79d..9c725c0a 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -592,7 +592,6 @@ impl Site { let mut context = Context::new(); let pages = self.pages.values() .filter(|p| p.meta.date.is_some()) - .take(self.config.rss_limit.unwrap()) // limit to the last n elements .cloned() .collect::>(); @@ -603,7 +602,8 @@ impl Site { let (sorted_pages, _) = sort_pages(pages, SortBy::Date); context.add("last_build_date", &sorted_pages[0].meta.date); - context.add("pages", &sorted_pages); + // limit to the last n elements) + context.add("pages", &sorted_pages.iter().take(self.config.rss_limit.unwrap()).collect::>()); context.add("config", &self.config); let rss_feed_url = if self.config.base_url.ends_with('/') { diff --git a/components/site/test_site/config.toml b/components/site/test_site/config.toml index 982d4f51..a9d8d86e 100644 --- a/components/site/test_site/config.toml +++ b/components/site/test_site/config.toml @@ -2,6 +2,8 @@ title = "My site" base_url = "https://replace-this-with-your-url.com" highlight_code = true compile_sass = true +generate_rss = true +rss_limit = 2 [extra.author] name = "Vincent Prouillet" diff --git a/components/site/test_site/content/posts/simple.md b/components/site/test_site/content/posts/simple.md index 2d4e6127..48fe505e 100644 --- a/components/site/test_site/content/posts/simple.md +++ b/components/site/test_site/content/posts/simple.md @@ -1,5 +1,5 @@ +++ -title = "Simple" +title = "Simple article with shortcodes" description = "" date = "2017-04-01" +++ diff --git a/components/site/tests/site.rs b/components/site/tests/site.rs index 5989a407..4a529088 100644 --- a/components/site/tests/site.rs +++ b/components/site/tests/site.rs @@ -395,3 +395,22 @@ fn can_build_site_with_pagination_for_index() { assert_eq!(file_contains!(public, "index.html", "has_prev"), false); assert_eq!(file_contains!(public, "index.html", "has_next"), false); } + +#[test] +fn can_build_rss_feed() { + let mut path = env::current_dir().unwrap().to_path_buf(); + path.push("test_site"); + let mut site = Site::new(&path, "config.toml").unwrap(); + site.load().unwrap(); + let tmp_dir = TempDir::new("example").expect("create temp dir"); + let public = &tmp_dir.path().join("public"); + site.set_output_path(&public); + site.build().unwrap(); + + assert!(Path::new(&public).exists()); + assert!(file_exists!(public, "rss.xml")); + // latest article is posts/simple.md + assert!(file_contains!(public, "rss.xml", "Simple article with shortcodes")); + // Next is posts/python.md + assert!(file_contains!(public, "rss.xml", "Python in posts")); +}