From 56c5036abcf0f809b5e2a7d714c69c1d4e7234b7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 9 Oct 2018 20:20:09 -0600 Subject: [PATCH] Allow inclusion of all items in RSS feeds. Switch to an `Option` for the serialized value of `rss_items`. This lets us just set a blank value in the configuration and thereby include *all* items. This is a backwards-compatible change; it does not affect the behavior of existing configurations. Fixes #468. Closes #471. --- components/config/src/config.rs | 12 ++++++------ components/site/src/lib.rs | 5 +++-- .../documentation/getting-started/configuration.md | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/components/config/src/config.rs b/components/config/src/config.rs index 2479cc12..47ff3d86 100644 --- a/components/config/src/config.rs +++ b/components/config/src/config.rs @@ -5,13 +5,13 @@ use std::path::{Path, PathBuf}; use chrono::Utc; use globset::{Glob, GlobSet, GlobSetBuilder}; +use syntect::parsing::{SyntaxSet, SyntaxSetBuilder}; use toml; use toml::Value as Toml; -use syntect::parsing::{SyntaxSet, SyntaxSetBuilder}; -use theme::Theme; -use highlighting::THEME_SET; use errors::{Result, ResultExt}; +use highlighting::THEME_SET; +use theme::Theme; // We want a default base url for tests static DEFAULT_BASE_URL: &'static str = "http://a-website.com"; @@ -76,8 +76,8 @@ pub struct Config { /// Whether to generate RSS. Defaults to false pub generate_rss: bool, - /// The number of articles to include in the RSS feed. Defaults to 10_000 - pub rss_limit: usize, + /// The number of articles to include in the RSS feed. Defaults to including all items. + pub rss_limit: Option, pub taxonomies: Vec, @@ -251,7 +251,7 @@ impl Default for Config { highlight_theme: "base16-ocean-dark".to_string(), default_language: "en".to_string(), generate_rss: false, - rss_limit: 10_000, + rss_limit: None, taxonomies: Vec::new(), compile_sass: false, check_external_links: false, diff --git a/components/site/src/lib.rs b/components/site/src/lib.rs index 32b22131..b2cc3066 100644 --- a/components/site/src/lib.rs +++ b/components/site/src/lib.rs @@ -732,10 +732,11 @@ impl Site { pages.par_sort_unstable_by(sort_actual_pages_by_date); context.insert("last_build_date", &pages[0].meta.date.clone().map(|d| d.to_string())); - // limit to the last n elements + // limit to the last n elements if the limit is set; otherwise use all. + let num_entries = self.config.rss_limit.unwrap_or(pages.len()); let p = pages .iter() - .take(self.config.rss_limit) + .take(num_entries) .map(|x| x.to_serialized_basic()) .collect::>(); diff --git a/docs/content/documentation/getting-started/configuration.md b/docs/content/documentation/getting-started/configuration.md index 74c491c1..183bb6ef 100644 --- a/docs/content/documentation/getting-started/configuration.md +++ b/docs/content/documentation/getting-started/configuration.md @@ -37,8 +37,9 @@ highlight_theme = "base16-ocean-dark" # Whether to generate a RSS feed automatically generate_rss = false -# The number of articles to include in the RSS feed -rss_limit = 20 +# The number of articles to include in the RSS feed. Will include all items if +# not set (the default). +# rss_limit = 20 # The taxonomies to be rendered for that site and their configuration # Example: