Browse Source

Fix RSS feed; close #101

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
c61518225b
5 changed files with 30 additions and 4 deletions
  1. +6
    -1
      CHANGELOG.md
  2. +2
    -2
      components/site/src/lib.rs
  3. +2
    -0
      components/site/test_site/config.toml
  4. +1
    -1
      components/site/test_site/content/posts/simple.md
  5. +19
    -0
      components/site/tests/site.rs

+ 6
- 1
CHANGELOG.md View File

@@ -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


+ 2
- 2
components/site/src/lib.rs View File

@@ -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::<Vec<Page>>();

@@ -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::<Vec<_>>());
context.add("config", &self.config);

let rss_feed_url = if self.config.base_url.ends_with('/') {


+ 2
- 0
components/site/test_site/config.toml View File

@@ -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"

+ 1
- 1
components/site/test_site/content/posts/simple.md View File

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


+ 19
- 0
components/site/tests/site.rs 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_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"));
}

Loading…
Cancel
Save