Fix RSS feed; close #101

This commit is contained in:
Vincent Prouillet 2017-07-15 12:51:32 +09:00
parent 1eefb75900
commit c61518225b
5 changed files with 30 additions and 4 deletions

View file

@ -1,6 +1,11 @@
# Changelog # 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 - Parallelize all the things
- Add weight sorting - Add weight sorting

View file

@ -592,7 +592,6 @@ impl Site {
let mut context = Context::new(); let mut context = Context::new();
let pages = self.pages.values() let pages = self.pages.values()
.filter(|p| p.meta.date.is_some()) .filter(|p| p.meta.date.is_some())
.take(self.config.rss_limit.unwrap()) // limit to the last n elements
.cloned() .cloned()
.collect::<Vec<Page>>(); .collect::<Vec<Page>>();
@ -603,7 +602,8 @@ impl Site {
let (sorted_pages, _) = sort_pages(pages, SortBy::Date); let (sorted_pages, _) = sort_pages(pages, SortBy::Date);
context.add("last_build_date", &sorted_pages[0].meta.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::<Vec<_>>());
context.add("config", &self.config); context.add("config", &self.config);
let rss_feed_url = if self.config.base_url.ends_with('/') { let rss_feed_url = if self.config.base_url.ends_with('/') {

View file

@ -2,6 +2,8 @@ title = "My site"
base_url = "https://replace-this-with-your-url.com" base_url = "https://replace-this-with-your-url.com"
highlight_code = true highlight_code = true
compile_sass = true compile_sass = true
generate_rss = true
rss_limit = 2
[extra.author] [extra.author]
name = "Vincent Prouillet" name = "Vincent Prouillet"

View file

@ -1,5 +1,5 @@
+++ +++
title = "Simple" title = "Simple article with shortcodes"
description = "" description = ""
date = "2017-04-01" date = "2017-04-01"
+++ +++

View file

@ -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_prev"), false);
assert_eq!(file_contains!(public, "index.html", "has_next"), 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"));
}